Problem #1 (Program listing 11.1, 11.2, 11.3)
String read and write
//Solution .MODEL small .STACK 100h .DATA str db "Hello World$" str2 db 80 dup(0) crlf db 0dh, 0ah, '$' .CODE MAIN PROC mov ax, @data mov ds, ax mov es, ax lea di, str2 call read_str lea dx, crlf mov ah, 9 int 21h ; mov ah, 2 ; mov dl, 0dh ; int 21h ; mov dl,0ah ; int 21h lea si, str2 add si, 4 ; mov bx, 10 call print_str exit: mov ah, 4ch int 21h ENDP MAIN read_str proc push ax push di cld ;df=0 ;std ;df=1 xor bx, bx mov ah, 1 int 21h while1: cmp al, 0dh je end_while1 cmp al, 8h jne else1 dec di dec bx jmp read else1: stosb inc bx read: int 21h jmp while1 end_while1: pop di pop ax ret read_str endp print_str proc push ax push bx push cx push dx push si mov cx, bx jcxz p_exit cld mov ah, 2 top: lodsb mov dl, al int 21h loop top p_exit: pop si pop dx pop cx pop bx pop ax ret print_str endp end MAIN
Problem #2
String reverse using stosb and lodsb
//Solution to be done by students
Problem #3 (Program listing 11.4)
Counting vowels and consonants using scan string instruction
//Solution .MODEL small .STACK 100h .DATA string db 80 dup(0) vowels db 'AEIOU' consonants db 'BCDFGHJKLMNPQRSTVWXYZ' out1 db 0dh, 0ah, 'Vowels = $' out2 db ' Consonants= $' vowelct dw 0 consct dw 0 crlf db 0dh, 0ah, '$' .CODE MAIN PROC mov ax, @data mov ds, ax mov es, ax lea di, string call read_str mov si, di cld repeat: lodsb lea di, vowels mov cx, 5 repne scasb jne ck_const inc vowelct jmp until ck_const: lea di, consonants mov cx, 21 repne scasb jne until inc consct until: dec bx jne repeat mov ah, 9 lea dx, out1 int 21h mov ax, vowelct call outdec mov ah, 9 lea dx, out2 int 21h mov ax, consct call outdec exit: mov ah, 4ch int 21h ENDP MAIN outdec proc push ax push bx push cx push dx or ax, ax ;Check if ax is 0 jge @end_if1 push ax mov dl, '-' mov ah, 2 int 21h pop ax neg ax @end_if1: xor cx, cx mov bx, 10 @repeat1: xor dx, dx div bx push dx inc cx cmp ax, 0 jne @repeat1 mov ah, 2 @print_loop: pop dx add dl, '0' int 21h loop @print_loop pop dx pop cx pop bx pop ax ret outdec endp read_str proc push ax push di cld ;df=0 ;std ;df=1 xor bx, bx mov ah, 1 int 21h while1: cmp al, 0dh je end_while1 cmp al, 8h jne else1 dec di dec bx jmp read else1: stosb inc bx read: int 21h jmp while1 end_while1: pop di pop ax ret read_str endp print_str proc push ax push bx push cx push dx push si mov cx, bx jcxz p_exit cld mov ah, 2 top: lodsb mov dl, al int 21h loop top p_exit: pop si pop dx pop cx pop bx pop ax ret print_str endp end MAIN
Homework
1. Change the read_str and print_str procedures of problem 1 so that there is no necessity of counter of length of string. Simply add a $ at the end of string to identify end of string
2. Lab task 2
3. Change the code in problem 3 to check for both small letters and capital letters
4. Section 11.6
5. Chapter 9 problem 9
6. Chapter 9 problem 10
Submit You homework through this link
------------------------------- Discussions Chapter 8 problem 10 //solution mov ax, 0010000000000000b shl ax, 1 test ax, 1000000000000000b jz zf01 jmp zf11 l1: test ax, 0100000000000000b jz zf02 jmp zf12 jmp end_ zf01: mov bl, 0 jmp l1 zf11: mov bl, 1 jmp l1 zf02: mov bh, 0 jmp end_ zf12: mov bh, 1 end_: xor bl, bh cmp bl, 0 jz l2 OR AX, 0000000000000001b jmp end2 l2: and ax, 1111111111111110b end2: and ax, 0111111111111111b