NASM - Variable Basics

2019-09-22 07:52发布

问题:

I know that you can create a string in nasm by writing this:

mystring db 'Hello World'

But if I want to move a single character, let's say e, the second character in the string to the al register. How can I do that? Should I write

mov al, mystring+1

or something? And how do I make an int variable? Can I write:

myint db 4

回答1:

'mystring + 1' is the address of the second byte of the string.

mov al, mystring + 1

stores (the least significant byte of) that address in al. To indicate that you don't want to store the address but the byte located at that address, write this:

mov al, [mystring + 1]

To declare a four-bytes integer equal to say, 42, use:

myint dd 42



标签: assembly nasm