On drive M in your assembly directory, create a directory called week4.
Write programs called WEEK4A.ASM through to WEEK4B.ASM as below and save them to the WEEK4 directory.
NB:
After assembling and linking WEEK4A and WEEK4B, examine each program in the debugger.
e.g.
TD WEEK4A (will open the debugger and go through the code in week4a.exe)
(While in the debugger, pressing the F7 key will step through each line in your
program).
WEEK4A.ASM
Write an 8086 assembly language program to do the following:
-
Move 20h into ax
-
Move 30h into bx
-
Swap the contents of ax and bx (using no more than 3 mov instructions)
WEEK4B.ASM
Write an 8086 assembly language program to do the following:
-
Move 20h into ax
-
Move 30h into bx
-
Swap the contents of ax and bx (using no more than 1 xchg instruction).
WEEK4C.ASM
Key in the program below.
What value will you see in the debugger for ax after the first 3 instructions have exectued? – Check your answer by using the debugger.
Determine the value will you see in the debugger for bx after the first 3 instructions have exectued? – Check your answer by using the debugger.
Which is the source operand - ax or bx?
Which is the destination operand - ax or bx?
title week4c.asm
.model small
.stack 100h
.data
.code
mov ax,4
mov bx,5
add bx,ax
mov ax, 4C00h ; Terminate program
int 21h ; correctly
end
WEEK4D.ASM
title week4D.asm
.model small
.stack 100h
.data
.code
mov ax,5
mov bx,5
add ax,bx
mov ax, 4C00h ; Terminate program
int 21h ; correctly
end
What value will you see in the debugger for ax after the first 3 instructions have exectued? – Check your answer by using the debugger.
Determine the value will you see in the debugger for bx after the first 3 instructions have exectued? – Check your answer by using the debugger.
Exercise
Write down the hex values for each uppercase character from A through to Z.
The first two characters and the last character have been completed for you in the table below.
After you have completed the table on paper, check your answer on the internet.
Did you get it right – if not where did you go wrong?
Character ASCII Value – expressed in Hexadecimal
A 41
B 42
.
.
.
Z 5A
WEEK4E.ASM
Take the program below and work out on paper what is in each of the registers after each instruction is executed. – The first 2 instructions have been completed for you in Table A below.
After you have completed the table – check your answer using the debugger (td.exe).
What does the program print out when you run it?
Line No.
|
|
1
|
mov ah,02h ;
|
2
|
mov dl,43h ; 3 lines to print capital C
|
3
|
int 21h ;
|
|
|
4
|
sub dl,2 ; subtract 2 from value stored in dl
|
5
|
int 21h ; call os
|
|
|
6
|
add dl,17 ; add 2 to the value stored in dl
|
7
|
int 21h ; call os
|
The complete program is given below:
title week4E.asm
.model small
.stack 100h
.data
.code
mov ah,02h ;
mov dl,43h ; 3 lines to print capital C
int 21h ;
sub dl,2 ; subtract 2 from value stored in dl
int 21h ; call os
add dl,17 ; add 17 to the value stored in dl
int 21h ; call os
mov ax, 4C00h ; Terminate program
int 21h ; correctly
end
Table A
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
AX
|
0200
|
0200
|
02??
|
|
|
|
|
BX
|
0000
|
0000
|
|
|
|
|
|
CX
|
0000
|
0000
|
|
|
|
|
|
DX
|
0000
|
0043
|
|
|
|
|
|
WEEK4F.ASM
The program from week4E.asm printed the letters CAR. Note that only two mov instructions were used.
Complete the program by printing the letters CARLOW. – Do not add any mov instructions to the program than are already there.
The program will print CARLOW. It will have only two mov instructions.
Loop Exercises 1
WEEK4G.ASM
Write a loop to print all 26 uppercase letters (A through Z).
Program Output:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
WEEK4H.ASM
Write a loop to print all 26 lowercase letters in descending order:
Program Output:
zyxwvutsrqponmlkjihgfedcba
WEEK4I.ASM
Write a loop to print the digits 9 through to 0
Program Output:
9876543210
WEEK4J.ASM
Write a loop to print the following
Program Output:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
zyxwvutsrqponmlkjihgfedcba
WEEK4K.ASM
Write a loop to print ‘A’ 26 times.
Type in this program and get it to run.
WEEK4L.ASM
Write a program that takes in a single character.
Assume the character entered is a digit, n, in the range 1-9.
Print the first n digits.
E.g. user keys in 0 – Program Prints Out 0
E.g. user keys in 1 – Program Prints Out 01
E.g. user keys in 2 – Program Prints Out 012
E.g. user keys in 3 – Program Prints Out 0123
E.g. user keys in 4 – Program Prints Out 01234
E.g. user keys in 5 – Program Prints Out 012345
.
.
E.g. user keys in 9 – Program Prints Out 0123456789
You are to use one loop in your program.
Share with your friends: |