CSE 322 Fall 2018 Lab 9

      No Comments on CSE 322 Fall 2018 Lab 9

Problem #1 (Example 10.3)

String read and write

//Solution
.MODEL small
.STACK 100h
.DATA
w dw 10,15,30,40,50,60,70,80,90,'$'

crlf db 0dh, 0ah, '$'
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

mov ax, 0
lea si, w
start: 
mov bx, [si]
cmp bx, '$'
je end_
add ax, bx
add si, 2
jmp start

end_:

exit:
mov ah, 4ch
int 21h
ENDP MAIN
end MAIN

Problem #2 (Example 10.4, program listing 10.1)

Array (Each element is 16 bit) reverse procedure

//Solution
.MODEL small
.STACK 100h
.DATA
w dw 10,20,30,40,50,60,70,80,90,100

crlf db 0dh, 0ah, '$'
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

lea si, w 
mov bx, 10 
call reverse

end_:

exit:
mov ah, 4ch
int 21h
ENDP MAIN 
reverse proc
push ax
push bx
push cx
push dx
push si
push di
mov di, si
mov cx, bx
dec bx
shl bx, 1
add di, bx
shr cx, 1
xchgloop:
mov ax, [si]
xchg ax, [di]
mov [si], ax
add si, 2
sub di, 2
loop xchgloop 

pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
reverse endp
end MAIN

Problem #3 (Section 10.6,Program listing 10.4)

Two dimensional array usage.
Finding the average of different tests

//Solution
.MODEL small
.STACK 100h
.DATA
five dw 5
scores dw 67, 45, 98, 33
dw 70, 56, 87, 44
dw 82, 72, 89, 40
dw 80, 67, 95, 50
dw 78, 76, 92, 60
avg dw 5 dup(0)
crlf db 0dh, 0ah, '$'
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

mov si, 6
repeat:
mov cx, 5
xor bx, bx
xor ax, ax
for:
add ax, scores[bx+si]
add bx, 8
loop for

xor dx, dx
div five
mov avg[si], ax
sub si,2
jnl repeat


exit:
mov ah, 4ch
int 21h
ENDP MAIN 
end MAIN

Problem #4

Basic Xlat usage

//Solution
.MODEL small
.STACK 100h
.DATA 
hello db 10,11,12,13,14,15,16,17,18,19,20
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

lea bx, hello
mov al, 5
xlat ; XLAT uses the initial value n stored in al, and fetches the nth element from the array 


exit:
mov ah, 4ch
int 21h
ENDP MAIN 
end MAIN

Problem #5 (Section 10.7, Program listing 10.5)

Encoding and decoding mesage using XLAT instruction

//Solution
.MODEL small
.STACK 100h
.DATA 
; ABCDEFGHIJKLMNOPQRSTUVWXYZ
codekey db 65 dup(' '), 'XQPOGHZBCADEIJUVFMNKLRSTWY'
db 37 dup(' ') 
; ABCDEFGHIJKLMNOPQRSTUVWXYZ
decodekey db 65 dup(' '), 'JHIKLQEFMNTURSDCBVWXOPYAZG'
db 37 dup(' ') 
coded db 80 dup('$')
prompt db 'Enter a message: $'
crlf db 0dh, 0ah, '$'
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

MOV Ah, 9
LEA dx, prompt
int 21h

mov ah, 1
lea bx, codekey
lea di, coded 
while_:
int 21h
cmp al, 0dh
je endwhile
xlat 
mov [di], al
inc di
jmp while_
endwhile:
mov ah, 9
lea dx, crlf
int 21h

lea dx, coded
int 21h

lea dx, crlf
int 21h

mov ah, 2
lea bx, decodekey
lea si, coded
while1:
mov al, [si]
cmp al, '$'
je endwhile1
xlat
mov dl, al
int 21h
inc si
jmp while1
endwhile1:

exit:
mov ah, 4ch
int 21h
ENDP MAIN 
end MAIN

Problem #6

Change the code in problem 5 to encode and decode for both small letters and capital letters

//Solution
To be done by students

 

Problem #7

Change the code in problem 5 to encode in such way that a letter is replaced by three letters ahead.
For example A becomes D and B becomes E

//Solution
To be done by students

Homework
1. Change the code in problem 2 to work for array of 8-bit elements, which can be used to reverse string.
2. Section 10.3: Application of sorting. Program listing 10.2,10.3
3. Change the code in problem 3 to find the average test score of each students.
4. Chapter 9 problem 11
5. Chapter 9 problem 12
6. Chapter 10 problem 7
7. Problem#6
8. Problem#7

Submit You homework through this link

Leave a Reply

Your email address will not be published. Required fields are marked *