Академический Документы
Профессиональный Документы
Культура Документы
Attendance (10%):
LABORATORY NO. 1
Introduction to Assembly Language Programming Tools
I. Objective
To introduce the following assembly language programming tools:
DEBUG
Netwide Assembler (NASM)
Emulator 8086 (EMU8086)
A. DEBUG is a program included in the MS-DOS and PC-DOS operating systems that allows the programmer to monitor
program’s execution closely for debugging purposes. Specifically, it can be used to examine and alter the contents of
memory to enter and run programs, and to stop programs at certain points in order to check or even change data.
Figure 1 shows the DEBUG environment.
FLAGS
Commands in DEBUG
j.tio Lab1 2
A, the ASSEMBLE command. The assemble command is used to enter assembly language instructions into
memory.
- A <starting address>
The starting address may be given as an offset number, in which case it is assumed to be an offset into the
code segment, or the segment register can be specified explicitly.
U, the UNASSEMBLE command. The unassembled command displays the machine code in memory along
with their equivalent assembly language instructions. The command can be given in either format shown
below:
- U <starting address> <ending address>
- U <starting address> <L number of bytes>
If the U command is entered with no addresses after it: “U <return>”, then DEBUG will display 32 bytes
beginning at CS:IP.
G, the GO command. The GO command instructs DEBUF to execute the instructions found between the
two given addresses. Its format is:
- G <=starting address> <stop address(es)>
If no addresses are given, DEBUG begins executing instructions at CS:IP until a breakpoint is reached. After
a breakpoint is reached, DEBUG displays the register contents and returns you to the command prompt. Up
to 10 stop addresses can be entered.
DEBUG will stop execution at the first of these breakpoints that it reaches.
T, the TRACE command. The trace command allows you to trace through the execution programs one or
more instructions at a time to verify the effect of the programs on registers and/or data. Its format is:
- T <=starting address> <number of instructions>
The trace command functions similarly to GO command in that if no starting address is specified, it starts at
CS:IP.
j.tio Lab1 3
Its format is :
- N <drive name:> <filename> <extension name>
After the code has been entered with the A command, CX must be set to contain the number of bytes to be
saved and register BX must be set to 0.
W, the WRITE command. The write command is used to save instructions onto a disk. Its format is:
-W
L, the LOAD command. The load command performs the opposite function of Write command. It loads
from disk into memory starting at the specified address. Its syntax is:
-L
B. NASM is an acronym for Netwide Assembler, unlike DEBUG that is specifically for debugging purposes, this software
assembles program written in assembly in any platform. NASM Integrated Development Environment (NASMIDE) is
complete software that has an editor, assembler and builder. Figure 2 is the NASMIDE environment.
Note: Use Help option to explore the environment.
;NASM-IDE ASM Assistant Assembler Project File
MAIN:
jmp START
DISP:
mov ah,09h ;String Print int service
int 21h
NASM Program
ret Structure:
START:
lea dx,[msg1] ;Display message
call DISP Setting of bit mode and IP
END: address
mov ah, 4ch ;End of program
int 21h
j.tio Lab1 4
section .data
msg1 db 13,10,‘Hello World!','$'
Main Program
Data Assignment
C. EMU8086 is an 8086 machine emulator licensed software. It provides a virtual machine to emulate 8086-
microprocessor system and provides assembly language programming and simulation. Figure 3 shows the EMU8086
environment.
Emu8086 combines an advanced source editor, assembler, disassembler, software emulator (Virtual PC) with
debugger.
IV. Procedure
DEBUG Environment
1. Type DEBUG at the command prompt of DOS then press ENTER key.
2. Command: R
j.tio Lab1 5
A. You will see a dash “-“ prompt that signifies DEBUG environment. Type R/r on this prompt then ENTER key.
Illustrate the output:
B. Type the following commands. Write the contents or observation on the space provided:
C. Write the appropriate command to modify the contents of the following registers.
3. Command: A
Assemble the given program at the starting offset address 100h. Type A 100 then press ENTER key. Encode the
program written below:
4. Command: U
A. Write the command that will unassemble the program in number 3:
Command: __________________________________________
5. Command: G
A.Execute the program in number 3. Type the given command
Command: –g =0100
j.tio Lab1 6
AX BX CX
6. Command: T
A.Reset the values of AX, BX and CX and set value of IP to 0100.
B. Execute program given in number 3 using trace command.
C.Type T or t at the DEBUG prompt, then press ENTER key. Repeat this step until all instructions are executed.
D.What are the contents of the following registers after executing each instruction?
INSTRUCTION AX BX CX
MOV AX,1
MOV BX,2
MOV CX,3
ADD AX,BX
ADD AX,CX
7. Command: D
A. Illustrate or describe the output after executing the following D commands:
COMMAND OUTPUT
D 100 10F
D CS:110 120
B. Fill the following blocks of memory with the specified data. Write the appropriate command.
BLOCK OF MEMORY DATA COMMAND
100 - 110 00
j.tio Lab1 7
9. Command: E
A.Enter the data ‘John Snith’ at starting address 100h:
Command: ______________________________________
B. Modify the data ‘John Snith’ to ‘John Smith’ (ASCII code of m=6D)
Command: ______________________________________
10. Command: N, W, L
A.Assemble the given program at starting address 100h. Write the command on the space provided.
Command: ____________________________________
CS:0100 MOV CX,05
CS:0103 MOV BX,0200
CS:0106 MOV AL,0
CS:0108 ADD AL,[BX]
CS:010A INC BX
CS:010B DEC CX
CS:010C JNZ 0108
CS:010E MOV [0205],AL
CS:0111 INT 3
B. Name the file ”LAB1.com” and save it in drive C. Set the value of CX with the total number of bytes of the
program and set BX to 0 before saving. Write the commands for naming and saving the file.
Command (Naming): ____________________________
Command (Saving): _____________________________
Note: Check the file in drive C.
C.Exit from DEBUG and load the saved file (LAB1.com) by typing DEBUG LAB1.com from the DOS prompt. Use
Unassemble command; do you see the program code LAB1.com? ________
NASMIDE Environment
section .data
msg1 db ‘Hello World’,13,10,’$’
j.tio Lab1 8
if (x <> 0) section .text
statements here(TRUE) cmp al,0 ;al is representing x
else jz TRUE
statements here(FALSE) jmp FALSE
11. Run the NASMIDE software located at c:\NASM. Type NASMIDE at the prompt
C:\NASM\> nasmide
12. Write the code below in NASMIDE editor and save it as printf.asm.
BITS 16
ORG 0x0100
; Display String
[section .text]
MAIN:
jmp START
DISP:
mov ah,09h ;String Print INT service
int 21h
ret
START:
lea dx,[msg] ;Display message
call DISP ;call DISP subroutine program
END:
mov ah, 4ch ;End of program
int 21h
section .data
msg db ‘Welcome to COMSYLA!’,13,10,’$’
j.tio Lab1 9
13. Run the program (a shortcut key to run the code is CTRL-F9). Illustrate the output on the space provided.
14. Create another code (given below) in NASMIDE editor and save it as scanf.asm.
BITS 16
bits
ORG 160x0100
org 0x0100
; Input a number and display
[section
; Author:.text]
J. TIO
[section
MAIN: .text]
MAIN:
jmp START
DISP: jmp START
DISP:
mov ah, 09h
mov ah,09h ;string print
intint21h
21h
retret
ONE:
START:
lealea dx,[msg2]
dx,[msg]
call call
DISPDISP
jmpmov ah,1
START ;input char
TWO: int 21h ;char entered placed to al
END:
lea dx,[msg3]
mov ah, 4ch ;End of program
call DISP
int 21h
jmp START
THREE:
section .data
lea
msg db dx,[msg4]
“Input a number: ”,”$”
15. Compile and run
call the program. Illustrate the output on the space provided.
DISP
jmp START
ELSE:
lea dx,[msg5]
call DISP
jmp END
START:
16. Create another
lea dx,code[msg1]
(given below) in NASMIDE editor and save it as if.asm.
call DISP
mov ah, 1
int 21h
cmp al,'1'
je ONE
cmp al,'2'
je TWO
cmp al,'3'
je THREE
jmp ELSE
END:
mov ah, 4ch
int 21h
section .data
msg1 db 'Input numbers from 1 to 3: ','$'
msg2 db 13,10,'The number entered is ONE $'
j.tio Lab1 entered is TWO $'
msg3 db 13,10,'The number 10
msg4 db 13,10,'The number entered is THREE $'
msg5 db 13,10,'The number entered is NOT WITHIN THE RANGE $'
c:\NASM\> printf
EMU8086 Environment
20. Invoke EMU8086 software.
21. Click the Samples Icon then choose Hello file.
22. Click Emulate icon, then choose Run icon.
23. Illustrate the output.
j.tio Lab1 11
24. Close the Emulator, then repeat steps 21 and 22 now choose traffic_lights file. Click Stop icon if you want to stop
running the code. Describe the output.
22. Close the Emulator, then create a new file, choose COM template.
23. Write the given code below and save it as samplecode.asm.
MOV AH,4CH
INT 21H
#make_COM#
;The 1st byte of the buffer area contains the maximum number of keyboard char.
;The 2nd byte of the buffer contains the count of the actual number of char typed.
;The remaining locations in the buffer contain the ASCII keyboard data.
;
;Source: pg 238 of The Intel Microprocessors by Barry Brey
j.tio Lab1 12
26. Compile and run the program.
27. Input the string “COMSYLA!”. Illustrate the output on the space provided.
V. Programming Problems
1. Trace the given code below using DEBUG. Write the register and flag’s content on the space
provided. Verify the result by computing it manually.
2. Make an assembly program that will translate decimal values (0 to 15) to its equivalent
hexadecimal code. Use EMU8086.
Example:
j.tio Lab1 13
3. Make an assembly program that will display the equivalent alphanumeric characters of ASCII
codes 41h to 49h using loop. Use NASMIDE.
Example:
j.tio Lab1 14