Defining Data


The following program subtracts an input value from a value 5000h using 16-bit signed integers.

Sub.asm
TITLE  Subtraction (5000h - Y)    (Sub.asm)
Comment |
*  Description: This program subtracts two 16-bit signed integers.
*  Insert a call DumpRegs statement to display the register values.
| 

INCLUDE Irvine32.inc
.data
  prompt1    BYTE  0Dh, 0Ah, "Calculate an Expresssion of 5000h - Y:"
             BYTE  0Dh, 0Ah, "Enter the value of operand Y: ", 0
  prompt2    BYTE  0Dh, 0Ah, "The result is ", 0
  X         SWORD  5000h
  Y         SWORD  ?
  finalVal  SWORD  ?

.code
main PROC
  mov   edx, OFFSET prompt1
  call  WriteString
  call  ReadInt
  mov   Y, ax                 ; Y: input
  sub   ebx, ebx              ; clear ebx
  mov   ax, X                 ; load ax with 5000h
  mov   bx, Y                 ; load bx with the input
  sub   ax, bx                ; ax = 5000h - Y
  mov   finalVal, ax          ; store the result
  mov   edx, OFFSET prompt2
  call  WriteHex              ; display the difference
  call  DumpRegs              ; display the registers
  exit
main ENDP
END  main
An Execution Example

 Calculate an Expression of 5000h – Y:
 Enter the value of operand Y: 400 

 The result is  00004E70

 EAX=00004E70  EBX=00000190  ECX=004010FF  EDX=00406054
 ESI=004010FF  EDI=004010FF  EBP=0019FF84  ESP=0019FF78
 EIP=004036A1  EFL=00000202  CF=0  SF=0  ZF=0  OF=0  AF=0  PF=0

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

DumpRegs Procedure
The procedure, which is from the link library, displays some registers in hexadecimal. It also displays the values of some flags. can be useful when debugging programs because it lets you display a snapshot of the CPU state while the program is running.




      Doctor: You’re overweight.
      Patient: I think I want a second opinion.    
      Doctor: You’re also ugly.