Reputation: 37
I am just learning NASM and I am kind of struggling to figure this out. How do you declare variables in NASM? For example, how would you declare unsigned int i
in NASM? Thanks
Upvotes: 3
Views: 8739
Reputation: 358
there is no such thing as unsigned int in assembly language (as far as I know). In NASM you can only declare memory locations and put contents in it. example:
section .data
abyte: db 15
aword: dw 452
adword: dd 478569
; etc etc see Nasm manual for more 'types'
The way you treat the variables will make you to use signed or unsigned values. When you need signed values the keep in mind that div and mul only works for unsigned values. (The MSB is not the sign bit). In that case you should use idiv and imul (integer division or signed division). Also keep in mind that the negative of a value will be shown as two's complement. You will see for 5 (in AX as example) : 0000000000000101 binary but for -5 you will see 1111111111111011 which is the two's complement of 5. both added gives 5 + (-5) or 0000000000000101 + 1111111111111011 = 0000000000000000. The overflow flag will be set appropriatly to indicate that there is an overflow when both numbers are treated as unsigned, so sometimes you can ignore this. A good practice is to debug and check often the flag status. To check if AX is negative or not you can and ax, ax and the sign flag will be 1 if the MSB is 1 otherwise 0. (js and jns instructions)
The answer is a bit late but for those who have the same question.....
Upvotes: 5