Sample Assembly Programs

It's time to look at some simple assembly language programs:


Program #1:

;*************************************************
; Purpose: Simple addition & subtraction 
;          using 32-bit registers
;*************************************************

TITLE sample1.asm

INCLUDE Irvine32.inc

.code
main PROC

	mov eax, 2h		; EAX = 2h
	add eax, 3h		; EAX = 5h
	sub eax, 1h		; EAX = 4h
	call DumpRegs           ; library routine to display register info

	exit                    ; return  control to Operating System
main ENDP
END main

If you install the software from the back of your book, you can invoke the assembler to assemble the above 32-bit program as follows:

make32 sample1 
If no errors exist, this produces an executable called sample1.exe. Executing the program will dump the registers EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP, EFL, CF SF ZF OF.

So what might a 16-bit program to do the same thing look like?


Program #2:

;*************************************************
; Purpose: To show simple addition and subtraction
;          using 16-bit registers and a data 
;          segment
;*************************************************

INCLUDE Irvine16.inc

.data
v1     dword  2h
v2     dword  4h
v3     dword  1h
rslt   dword  ?

.code
main PROC
          mov ax, @data    ; place the address of data seg in ax
          mov ds, ax       ; initialize DS to address of data seg
          mov eax,v1       ; place 2h in eax
          add eax,v2       ; add 4h to eax
          sub eax,v3       ; subtract 1h from eax
          mov rslt,eax     ; store the result (5h)
          call DumpRegs    ; display the registers

	  exit             ; return control back to the Operating System
main ENDP
END main
Between now and the next time we get together, get the 16-bit version of this program running.