| Operand | Description |
|---|---|
| reg | An 8-, 16-, or 32-bit general register |
reg8, reg16, reg32 |
A general register, identified by its number of bits |
segreg |
A 16-bit segment register |
mem |
A memory operand, using any of the standard memory addressing modes |
mem8, mem16, mem32 |
A memory operand, identified by its number of bits |
accum |
AL, AX, or EAX |
immed |
An immediate operand |
immed8, immed16, immed32 |
An immediate operand, identified by its number of bits |
[offset]: Dereferences the offset and obtains the contents of memory.
MASM normally treats X same as the [X], where X is a variable.
OFFSET operator returns the offset of a data label.
| An Immediate Operand | A Memory Operand | Dereference |
.code mov eax, -5000h call WriteHex |
.data X SDWORD -5000h .code mov eax, X call WriteHex |
.data X SDWORD -5000h .code mov eax, [X] call WriteHex |
| Output | Output | Output |
| Offset | Dereference | Offset then Dereference |
.data X SDWORD -5000h .code mov eax, offset X call WriteHex |
.data X SDWORD -5000h .code mov eax, [offset X] call WriteHex |
.data X SDWORD -5000h .code mov ebx, offset X mov eax, [ebx] call WriteHex |
| Output | Output | Output |
| ReadSub.asm |
COMMENT!
*
* This program reads and subtracts 32-bit hexadecimal integer from 50000h.
*
!
INCLUDE Irvine32.inc
.data
prompt1 BYTE 0Dh, 0Ah, "Calculate an Arithmetic Expression of 50000h - Y:",
0Dh, 0Ah, 0
prompt2 BYTE "Enter the value of operand Y: ", 0
prompt3 BYTE 0Dh, 0Ah, "The result is ", 0
X DWORD 50000h
Y DWORD ?
result DWORD ?
.code
main PROC
mov edx, OFFSET prompt1
call WriteString ; print prompt1
mov edx, OFFSET prompt2
call WriteString ; print prompt2
call ReadHex
mov Y, eax ; Y = eax (the input)
mov eax, X ; eax = X (50000h)
; calculate 50000h – Y
sub eax, Y ; eax = X (50000h) – Y (the input)
mov result, eax ; result = eax (X – Y)
mov edx, OFFSET prompt3
call WriteString ; print prompt3
call WriteHex ; print eax (result)
exit
main ENDP
END main
|
| An Execution Example |
Calculate an Arithmetic Expression of 50000h – Y: Enter the value of operand Y: 4000 The result is 0004C000 |
|
“I am so clever that sometimes I don’t understand a single word of what I am saying.” — Oscar Wilde |