.model smal1 .stack 100h .code main proc mov ah, 1 int 21h ; enter key routine m
ID: 3877091 • Letter: #
Question
.model smal1 .stack 100h .code main proc mov ah, 1 int 21h ; enter key routine mov cl, alsaving the key pressed from AL into CL mov ch, al mov bl, 8 my counter binloop: shl cl, 1 jc displ mov dl, 30h call disp dec bl i dec the counter by 1 jnz binloop call hex 4c00h terminate the program and return to mov ax, int 21h displ: MSDOs mov dl, 31h call disp dec bl i dec the counter by 1 jnz binloop call hex 4c00h mov ax, int 21h terminate the program and return to MSDOs hex proc mov cl, ch call shrcl mov dl, cl add dl, 30h call disp mov cl, ch call shlcl call shrcl mov dl, cl add dl, 30h call disp retExplanation / Answer
.model small //every module have segment(like code,data,stack) must begin with .model directive
.stack 100h //starting stcak segment of 100h size
.code //starting code segment where our actual program lies
main proc //this starting main of name proc
mov ah,1; //we are moving 1 to ah register
int 21h; //it is software interrupt that invokes DOS API functions
mov cl,al; //moving the data at al register to cl register
mov ch,al; //moving the data at al register to ch register
mov bl,8; //moving constant value 8 to register bl
binloop: //this is a label named binloop,at miidle of code ,if we want to,we can come back to this part and can run code
shl cl,1; //left shifts value at cl by 1 byte
jc displ //jc-(jump on carry).if we get carry while shifting value in cl ,we goes to displ
mov dl,30h; //move 30h into dl register
call disp; //it called unconditional sub-routine.Without any condition, we automatically goes to disp label
dec bl; //decrement bl register value by 1
jnz binloop; //jnz-(jump on non zero).If bl value is not equal to zero,we jumps to binloop label
call hex; //directly jumps to hex sub-routine
mov ax,4c00h; //moving 4c00h value to ax register
int 21h; //terminate program.
displ: //this is label named displ
mov dl,31h; //move 31h value into dl register
call disp; //jumps to disp sub-routine
dec bl; // decrement value at bl register by one
jnz binloop //if bl is nt equal to zero,jumps to binloop
call hex //calls sub-routine hex
mov ax,4c00h //mov 4c00h value to ax register
int 21h; //terminates program
hex proc //this subroutine named hex
mov cl,ch ..moving value at h register to cl register
call shrcl //calls sub-routine shrl
mov dl,cl //moves value at cl register to dl register
add dl,30h //adds 30h to value at dl regsiter and stores in dl regsiter
call disp //calls sub-routine disp
mov cl,ch //moves value at ch register to cl register
call shlcl //calls sub-routine shlcl
call shrcl //calls sub-routine shrcl
mov dl,cl //moves value at cl register to dl register
add dl,30h //adds value 30h to value at dl and stores in dl
call disp // calls sub-routine disp
ret //returns to original execution from where you come to this sub-routine
hex proc //thsi is sub-routine proc
mov cl,ch //moves value at cl register to ch register
call shrcl //calls sub-routine shrcl
mov dl,cl //moves value at cl regsiter to dl register
add d1,30h //adds value 30h to value at dl register and stores in dl register
call disp //calls sub-routine disp
ret //returns to original execution from where we come to this sub-routine
hex endp //endp-(end of procedure).thsi is end of procedure hex
shrcl proc //this sub-routine shrcl
shr c1,1 //shifts right cl register by one byte
shr c1,1 //shifts right cl register by one byte
shr c1,1 //shifts right cl register by one byte
shr c1,1 //shifts right cl register by one byte
ret //returns to original execution from we come to this sub-routine
shlcl endp //this is end of procedure of shlcl
disp proc //this is sub-routine disp
cmp dl,39h //moves 39h value to dl register
js skip //js-(jump if sign flag is set),if sign sets because of above instruction,goes to skip label
add dl,7 //adds value 7 to value at register dl and stores in dl regsiter
skip: //this label named skip
mov ah,6 //moves value 6 to ah register
int 21h //terminates the procedure
ret //returns to original execution from where we come to this sub-routine
disp endp //this end of procedure of disp
main endp //end of procedure of main
end main //ends main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.