1
segment .data
num1: db 40
num2: db 2
num3: db 44

segment .text
        global  asm_main
asm_main:
        enter   0,0               
        pusha

        mov     eax,[num1]
        add     eax,[num2]
        call    print_int
        call    print_nl

        mov     eax,[num3]
        sub     eax,[num2]

        call    print_int
        call    print_nl

        popa
        mov     eax, 0            
        leave
        ret

The code above was given

This prints out 623652394 1143264298

My professor says to use dump_regs macro to make this print "42" and I'm not sure how to do that.

  • `db` is only 1 byte, but you load 4. You probably want `dd`, or use `movzx` load and byte operand-size for add or sub. – Peter Cordes Sep 29 '20 at 01:11
  • Hi, interesting, not sure if this might be of interest https://stackoverflow.com/questions/22181320/writing-out-a-single-register-in-assembly – IronMan Sep 29 '20 at 01:12
  • 2
    @IronMan: Printing registers isn't the problem. This is getting the wrong values into regs in the first place by doing a dword load that overlaps multiple bytes. – Peter Cordes Sep 29 '20 at 01:13
  • "db" was a given input. My professor wants me to start with that. – user14358127 Sep 29 '20 at 02:29
  • 1
    Ok, then do a byte and sub instead of dword, or do zero-extending loads with movzx like shown in [Loading a register from a "db 0" doesn't load a 0 into EAX?](https://stackoverflow.com/q/43014135) – Peter Cordes Sep 29 '20 at 03:03
  • 1
    [Average of marks with bytes](https://stackoverflow.com/q/52541787) shows how to use movzx with `db` to do math after zero-extending. – Peter Cordes Sep 29 '20 at 03:25

0 Answers0