Instructions


An instruction is a statement that is executed by the processor at runtime after the program has been loaded into memory and started. An instruction contains four basic parts: (i) label, (ii) instruction mnemonic, (iii) operands, and (iv) comment. The basic syntax is
   [label:]   mnemonic   operand(s)   [; comment]
Label (optional)
A label is an identifier that acts as a place marker for either instructions or data. It could be a data label, identifying the location of a variable, such as
   prompt3  BYTE   0Dh, 0Ah, "The result is  ", 0
or it could be a code label, used as target of jumping and looping instructions, such as
   L1:    mov   eax, 5000h
Instruction Mnemonic (required)
An instruction mnemonic is a short word that identifies the operation carried out by an instruction. For example,
   mov    edx, OFFSET prompt3
Operand(s) (usually required)
An assembly language instruction can have between 0 and 3 operands, each of which can be a register, memory operand, constant expression, or I/O port.

Comment (optional)
Comments are a useful way for the programmer to communicate information about how the program works to a person reading the code. For example,
   call   WriteString              ; print prompt1
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

The white italic text with a navy background color is entered by users.




      “Creativity takes courage. But, mostly, it takes coffee.”    
      — Henri Matisse