Question: Correct the following assembly code for processor 8086. The code should use the str aaabccddd and reduce it to abcd. [org 0x100] jmp start str1:
Correct the following assembly code for processor 8086. The code should use the str aaabccddd and reduce it to abcd.
[org 0x100] jmp start str1: db 'aaabccddd',0 actionFlag: db 0
strlen: push bp mov bp,sp push es push cx push di les di, [bp+4] ; point es:di to string mov cx, 0xffff ; load maximum number in cx xor al, al ; load a zero in al repne scasb ; find zero in the string mov ax, 0xffff ; load maximum number in ax sub ax, cx ; find change in cx dec ax ; exclude null from length pop di pop cx pop es pop bp ret 4
deletePair: push bp mov bp,sp pusha
mov dx,[bp+4] ;index mov bx,[bp+6] ;string push ds push bx call strlen mov cx,ax mov di,bx add di,dx mov si,di add si,2 sub cx,dx sub cx,1
cld rep movsb popa pop bp ret 4
reduceString: push bp mov bp,sp pusha
mov bx,[bp+4] mov si,0 mov di,1 mov byte[actionFlag],0 push ds push bx call strlen mov cx,ax dec cx loopit: mov dl,[bx+si] cmp dl,[bx+di] jne skip push bx push si call deletePair mov byte[actionFlag],1 jmp exit skip: add di,1 add si,1 cmp di,cx jne loopit
exit: popa pop bp ret 2
irreducibleString: push bp mov bp,sp pusha mov bx,[bp+4]
reduceLoop: push bx call reduceString cmp byte[actionFlag],0 jne reduceLoop
popa pop bp ret 2
start: mov ax,str1 push str1 call irreducibleString
mov ax,0x4c00 int 21h
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
