Está en la página 1de 6

NCP 312 (Computer Organization With

Assembly Language Laboratory)

EXPERIMENT 7
PROCESSING ASCII & BCD DATA
I. OBJECTIVE
1. To examine ASCII and BCD data formats.
2. To perform arithmetic and to cover conversions between these formats and
binary.
II. INSTRUCTIONS / SERVICES
A.
o
o
o
o

Instruction that perform arithmetic directly on ASCII number:


AAA ASCII adjust for Addition
AAD ASCII adjust for Division
AAM ASCII adjust for Multiplication
AAS ASCII adjust for subtraction

Note: These instruction are coded without operands and automatically adjust the AX
register.
B. ASCII Addition
The AAA/AAS operations check the rightmost hex digit (4 bits) of the AL register. If
the digit is between A to F or the auxiliary carry flags is 1, the operation adds 6 to the
AL register, adds 1 to the AH register, and sets the carry auxiliary carry flags to 1.
Consider the effect of adding the ASCII number 8 and 4;
0038H
0034H

AX
BX

Addition and adjustment are as follows:


ADD AL, BL
; add hex 34 to hex 38
AAA
; Adjust for ASCII addition
Effect:
After the ADD
: 006C
After the AAA
: 0102
To restore the ASCII representation:
OR AX, 3030H

; Result now 3132H at AX

C. ASCII Subtraction
Consider the following:
hex 38
hex 34
AX
mov al, asc1
sub al, asc2
AAS
1 | Page

asc1
asc2
F
; 0038
; 0004
; 0004

0
0

NCP 312 (Computer Organization With


Assembly Language Laboratory)

D. ASCII Multiplication
The AAM instruction corrects the result of multiplying ASCII data in the AX register. It
divides the AL by 10 (hex 0A) and stores the quotient in the AH and the remainder in
the AL.
Consider the following:
hex 35
AL
hex 39
CL
and cl, 0Fh ; convert cl to 09
and al, 0Fh ; convert al to 05
mul cl
; multiply al by cl
AAM
; convert to unpacked decimal
or ax, 3030h ;convert to ASCII
E. ASCII Division
The AAD instruction provides a correction of an ASCII dividend prior to dividing. It
allows for a two bytes dividend in the AX.
Consider the following:
hex 3238
hex 37
and CL, 0Fh
AAD
div CL

2 | Page

AX (dividend)
CL (divisor)
;convert to unpacked 0208
; convert to binary
; divide by 7

NCP 312 (Computer Organization With


Assembly Language Laboratory)

EXERCISE
NAME:

INSTRUCTOR:

SECTION:

DATE:

GRADE:

1. Encode the following program:


cseg segment para 'code'
assume cs:cseg, ds:cseg,
es:cseg, ss:cseg
org 100h
start:
jmp begin
num1 db '9'
num2 db '7'
msg db 'The Result is $'
begin:
mov ax, 0003h
int 10h
mov ah, 00h
mov al, num1
add al, num2
aaa
or ax, 3030h

mov bx, ax
mov ah, 09
lea dx, msg
int 21h
mov
mov
int
mov
mov
int

ah,02
dl, bh
21h
ah, 02
dl, bl
21h

int 20h
cseg ends
end start

What is the output message?

Try to change the values (single digit only) of num1 and num2 and observe the value on
the output message. What does the program perform?

3 | Page

NCP 312 (Computer Organization With


Assembly Language Laboratory)

2. Encode the given program:


input macro string, reg1, reg2
mov ah, 09h
lea dx, string
int 21h
mov ah, 01h
int 21h
sub al, 30h
mov reg1, al
mov ah, 01h
int 21h
sub al, 30h
mov reg2, al
endm
cseg segment para 'code'
assume cs:cseg, ds:cseg,
es:cseg, ss:cseg
org 100h
start:
jmp begin
str1 db 'First Number:$'
str2 db 10,13,'Second
Number:$'
str3 db 10,13,'Total:$'
ones db ?
tens db ?
hund db ?
begin:

What is the output of the given program?

4 | Page

mov ax, 0003h


int 10h
input str1, bh, bl
input str2, ch, cl
sub bh,ch
mov ah,bh
sub bl,cl
mov al,bl
aas
or ax, 3030h
mov ones, al
mov tens, ah
mov ah, 09h
lea dx, str3
int 21h
mov
mov
int
mov
int

ah, 02h
dl, tens
21h
dl, ones
21h

int 20h
cseg ends
end start

NCP 312 (Computer Organization With


Assembly Language Laboratory)

3. Encode the given program:


input macro string, reg1, reg2, reg
mov ah, 09h
lea dx, string
int 21h
mov ah, 01h
int 21h
mov reg1, al
mov ah, 01h
int 21h
mov reg2, al
or reg, 3030h
endm
cseg segment para 'code'
assume cs:cseg, ds:cseg,
es:cseg, ss:cseg
org 100h
start:
jmp begin
str1 db 'First Number:$'
str2 db 10,13,'Second
Number:$'
str3 db 10,13,'Total:$'
x db ?
y db ?
z db ?
begin:
mov ax, 0003h
int 10h
input str1, bh, bl, bx
input str2, ch, cl, cx
add bl,cl
mov al,bl

What is the output of the given program?

5 | Page

mov ah,00h
aaa
mov z, al
add
add
mov
mov
aaa

bh,ch
bh,ah
al,bh
ah,00h

mov y, al
mov x, ah
add z, 30h
add y, 30h
add x, 30h
mov ah, 09h
lea dx, str3
int 21h
mov
mov
int
mov
int
mov
int

ah,
dl,
21h
dl,
21h
dl,
21h

02h
x
y
z

int 20h
cseg ends
end start

NCP 312 (Computer Organization With


Assembly Language Laboratory)

ACTIVITY
NAME:
SECTION:

DATE:

INSTRUCTOR:
GRADE:

Create a program in assembly language that will let the user input two 2-digit numbers
and then an operation (+ or -), the program will then compute for the appropriate total
for the given inputs.

6 | Page

También podría gustarte