Assigning value to variable in x86 (NASM)

后端 未结 2 1967
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 11:37

I have decided to learn assembler for fun. I have been coding in C for many years.

I followed some online tutorials that print \"Hello world\" and dug around a bit i

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 12:37

    To make a memory reference in nasm, you must surround the address with square brackets. Additionally, in each of the cases you've got here, you also need to specify a size, like so:

        mov byte [iter], 0     ; initalise loop counter
    FL: cmp byte [iter], 10    ; is iter == 10?
    
        inc byte [iter]
    

    In this case, though, it would probably make more sense to store iter in a register instead of in memory. You're clobbering most of the obvious ones with your system calls, but esi or edi look available.

提交回复
热议问题