Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question on subq argument ordering #2

Open
xysun opened this issue Feb 25, 2021 · 0 comments
Open

question on subq argument ordering #2

xysun opened this issue Feb 25, 2021 · 0 comments

Comments

@xysun
Copy link

xysun commented Feb 25, 2021

Hello,

I'm following the Essentials of Compilation book together with this code for the exercises. I find the ordering of subq argument is giving me surprising result, I feel I must be making a silly mistake somewhere, yet I cannot figure out where.. so here I am :)

here is my example X86Program:

(define i1 (Instr 'movq (list (Imm 0) (Reg 'rax))))
(define i2 (Instr 'subq (list (Imm 10) (Reg 'rax))))
(define instrs (list i1 i2))
(define block (Block '() instrs))
(define p (X86Program '() `((start . ,block))))
(println (interp-x86-0 p))

which essentially is

movq 0 %rax
subq 10 %rax

However, both interp-pseudo-x86-0 and interp-x86-0 gives me 10 instead of -10. If I swap the arguments to subq then I do get -10 back.

From reading both the x86 instruction quick reference from the book:

subq A, B map to B - A -> B

And in code:

(subq 2 ,(lambda (s d) (- d s)))

it seems they are consistent with my understanding of the ordering of arguments. What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant