Upload
emory-austin
View
213
Download
0
Embed Size (px)
Citation preview
LAB2
PROGRAM STRUCTURE
The assembly language program consist of code, data and stack.
Data segment: contains all the variable definition.
.DataCode segment: contains a program’s instructions.
.code name (name is optional)
Stack segment: to set aside a block of memory to store the stack
.stack size
PROGRAM STRUCTURE
.MODEL SMALL
.STACK 100H
.DATA; data definition go here
.CODE MAIN PROC;instruction go here MAIN ENDP;other procedures go here END MAIN
PROGRAMMING STEPS
Editor
.ASM File
Assembler
Linker
.OBJ File
.EXE File
Create source program
Assemble source program
Link object program
Q4: Complete the following assembly program:This program should load the value 6438h in AX and the value 9BC8h in BX, then add the two registers and store the result in CX.
A) Write the assembly program in notepad++ and save it as PGM7.asm
Q4:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AX, 6438h ; Store 6438h in AX
MOV BX, 9BC8h ; Store 9BC8h in BX
ADD AX,BX ; Adding AX and BX
MOV CX,AX ; Store the result in CX
;DOS Exit
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Q4: Use the usual steps to run the program, then using the DEBUG program, follow and answer the following:
How to use DEBUG :C:\ DEBUG PGM7.EXE
1. Display the register by write command –R2. What are the content of AX , BX, CX and DX registers at the beginning ?3. Trace Instructions by typing –T.4. After each instruction, write down the changes in registers and the values
of the flags (refer to the table below). 5. When you reach INT 21h, press: P, after that complete tracing using T
command.6. Finally exit the DEBUG by typing -Q
Q4:
Display the register by write command –R
What are the content of AX , BX, CX and DX registers at the beginning ?
Next instruction
Q4: Trace Instructions by typing –T.After each instruction, write down the changes in registers and the values of
the flags (refer to the table below).
Addition result Addition affects on flags 1 1 1 1
8 3 4 6+ 8 C B 9
0 0 0 0
FLAGS SYMBOL SET (1) SET (0)
OVERFLOW FLAG OF OV NV
DIRECTION FLAG DF DN UP
INTERRUPT FLAG IF EI DI
SIGN FLAG SF NG PL
ZERO FLAG ZF ZR NZ
AUXILIARY FLAG AF AC NA
PARITY FLAG PF PE PO
CARRY FLAG CF CY NC
TRAP FLAG TF
Q4: When you reach INT 21h, press: P, after that complete tracing using T
command.Finally if you want to exit the DEBUG, type :Q