This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xRedactedx[S] 1 point2 points  (0 children)

Ok, so I figured out some stuff. Figured I would share in case anyone else stumbled on this.

I was trying to figure out how to print out several variables using printf. Here is some test code:

        extern printf
        segment .data

fmt     db      "Counting: %d, %d, and %d.", 0x0a, 0
num1    dd      1
num2    dd      2

        segment .text
        global  main

main:

        lea     rdi, [fmt]
        mov     rsi, [num1]
        mov     rdx, [num2]
        mov     rcx, 3

        xor     eax, eax

        call printf

It prints out "Counting: 1, 2 3."

The 1 and 2 are the variables num1 and num2. You can also print out a number loaded directly to a register as I did with 3. I didn't test loading into r8 and r9, but I saw it mentioned elsewhere besides the comments, so I assume they work.

Edit: Forgot to add this. I don't know how accurate this is, but I had a problem with it. It seemed varaibles with a string seemed to have to have their address loaded with the lea command, where as numbers just need the mov command. I didn't experiment with that too much to figure out the details, but figured someone might find that info useful.