Slide 5.1: Programming Laboratory II: searching a string for a pattern
Slide 5.3: Intrinsic data types
Home

Defining Data


The following program Sub.asm subtracts two 16-bit signed integers, 2000h and 1000h, from a value 5000h, a 16-bit signed integer.

Sub.asm
 TITLE  Subtraction             (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
  x         SWORD   5000h
  y         SWORD   2000h
  z         SWORD   1000h
  finalVal  SWORD   ?

 .code
 main PROC
        sub   eax, eax          ; clear eax
        sub   ebx, ebx          ; clear ebx
        sub   ecx, ecx          ; clear ecx

	mov   ax, x             ; load ax with 5000h
        mov   bx, y             ; load bx with 2000h
        mov   cx, z             ; load cx with 1000h

	sub   ax, bx            ; subtract 2000h
	sub   ax, cx            ; subtrack 1000h
        mov   finalVal, ax      ; store the result (2000h)
	call  DumpRegs          ; display the registers
	exit
 main ENDP
 END  main

DumpRegs Procedure (textbook page 116)
The DumpRegs procedure, which is from the Irvine32.lib link library, displays some registers in hexadecimal. It also displays the values of some flags. The following is the output from the above program Sub.asm:
   EAX=00002000   EBX=00002000   ECX=00001000   EDX=BFFC94C0
   ESI=81A28644   EDI=00000000   EBP=0063FF78   ESP=0063FE3C
   EIP=0040103D   EFL=00000206   CF=0   SF=0   ZF=0   OF=0
DumpRegs can be useful when debugging programs because it lets you display a snapshot of the CPU state while the program is running.