☀️
Light
File Preview
8086_Assembly_Solutions_Q1_Q9.txt
============================================================ Question 1: Add two single-digit numbers ============================================================ .model small .stack 100h .data msg1 db "Enter first digit: $" msg2 db "Enter second digit: $" msg3 db "Sum = $" .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h ;input first digit mov ah,1h int 21h mov cl,al sub cl,48 ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h ;input second digit mov ah,1h int 21h mov bl,al sub bl,48 ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;add add cl,bl ;print msg3 mov ah,9h lea dx,msg3 int 21h ;print result mov ah,2h mov dl,cl add dl,48 int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 2: Subtract second digit from first digit ============================================================ .model small .stack 100h .data msg1 db "Enter first digit: $" msg2 db "Enter second digit: $" msg3 db "Result = $" .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h ;input first digit mov ah,1h int 21h mov cl,al sub cl,48 ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h ;input second digit mov ah,1h int 21h mov bl,al sub bl,48 ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;subtract sub cl,bl ;print msg3 mov ah,9h lea dx,msg3 int 21h ;print result mov ah,2h mov dl,cl add dl,48 int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 3: Uppercase letter to lowercase ============================================================ .model small .stack 100h .data msg1 db "Enter an uppercase letter: $" msg2 db "Lowercase = $" .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h ;input letter mov ah,1h int 21h mov cl,al ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;convert to lowercase add cl,32 ;print msg2 mov ah,9h lea dx,msg2 int 21h ;print result mov ah,2h mov dl,cl int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 4: Lowercase letter to uppercase ============================================================ .model small .stack 100h .data msg1 db "Enter a lowercase letter: $" msg2 db "Uppercase = $" .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h ;input letter mov ah,1h int 21h mov cl,al ;newline mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;convert to uppercase sub cl,32 ;print msg2 mov ah,9h lea dx,msg2 int 21h ;print result mov ah,2h mov dl,cl int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 5: Three uppercase letters -> lowercase, printed in reverse order (each on new line) ============================================================ .model small .stack 100h .data msg1 db "Enter first uppercase letter: $" msg2 db "Enter second uppercase letter: $" msg3 db "Enter third uppercase letter: $" msg4 db "Result (reversed, lowercase): $" c1 db ? c2 db ? c3 db ? .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h mov ah,1h int 21h mov c1,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h mov ah,1h int 21h mov c2,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg3 mov ah,9h lea dx,msg3 int 21h mov ah,1h int 21h mov c3,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;convert all three to lowercase mov al,c1 add al,32 mov c1,al mov al,c2 add al,32 mov c2,al mov al,c3 add al,32 mov c3,al ;print msg4 mov ah,9h lea dx,msg4 int 21h mov dl,10 mov ah,2h int 21h mov dl,13 int 21h ;print in reverse order: c3, c2, c1 (each on new line) mov ah,2h mov dl,c3 int 21h mov dl,10 int 21h mov dl,13 int 21h mov dl,c2 int 21h mov dl,10 int 21h mov dl,13 int 21h mov dl,c1 int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 6: Three lowercase letters -> uppercase, printed in reverse order (each on new line) ============================================================ .model small .stack 100h .data msg1 db "Enter first lowercase letter: $" msg2 db "Enter second lowercase letter: $" msg3 db "Enter third lowercase letter: $" msg4 db "Result (reversed, uppercase): $" c1 db ? c2 db ? c3 db ? .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h mov ah,1h int 21h mov c1,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h mov ah,1h int 21h mov c2,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg3 mov ah,9h lea dx,msg3 int 21h mov ah,1h int 21h mov c3,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;convert all three to uppercase mov al,c1 sub al,32 mov c1,al mov al,c2 sub al,32 mov c2,al mov al,c3 sub al,32 mov c3,al ;print msg4 mov ah,9h lea dx,msg4 int 21h mov dl,10 mov ah,2h int 21h mov dl,13 int 21h ;print in reverse order: c3, c2, c1 (each on new line) mov ah,2h mov dl,c3 int 21h mov dl,10 int 21h mov dl,13 int 21h mov dl,c2 int 21h mov dl,10 int 21h mov dl,13 int 21h mov dl,c1 int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 7: Digit + special character, displayed together in same order (e.g. 5@) ============================================================ .model small .stack 100h .data msg1 db "Enter a single digit: $" msg2 db "Enter a special character: $" msg3 db "Output: $" numc db ? specc db ? .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h mov ah,1h int 21h mov numc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h mov ah,1h int 21h mov specc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;print msg3 mov ah,9h lea dx,msg3 int 21h ;print in same order: digit then special char mov ah,2h mov dl,numc int 21h mov dl,specc int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 8: Special character + digit, displayed in reverse order (e.g. #,8 -> 8#) ============================================================ .model small .stack 100h .data msg1 db "Enter a special character: $" msg2 db "Enter a single digit: $" msg3 db "Output: $" specc db ? numc db ? .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h mov ah,1h int 21h mov specc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h mov ah,1h int 21h mov numc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;print msg3 mov ah,9h lea dx,msg3 int 21h ;print in reverse order: digit then special char mov ah,2h mov dl,numc int 21h mov dl,specc int 21h ;exit mov ah,4ch int 21h main endp end main ============================================================ Question 9: Uppercase, lowercase, digit -> print lowercase, uppercase, digit (e.g. A,b,7 -> a, B, 7) ============================================================ .model small .stack 100h .data msg1 db "Enter an uppercase letter: $" msg2 db "Enter a lowercase letter: $" msg3 db "Enter a single digit: $" msg4 db "Output: $" sep db ", $" upc db ? lowc db ? numc db ? .code main proc mov ax,@data mov ds,ax ;print msg1 mov ah,9h lea dx,msg1 int 21h mov ah,1h int 21h mov upc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg2 mov ah,9h lea dx,msg2 int 21h mov ah,1h int 21h mov lowc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h ;print msg3 mov ah,9h lea dx,msg3 int 21h mov ah,1h int 21h mov numc,al mov ah,2h mov dl,10 int 21h mov dl,13 int 21h mov dl,10 int 21h mov dl,13 int 21h ;convert uppercase -> lowercase mov al,upc add al,32 mov upc,al ;convert lowercase -> uppercase mov al,lowc sub al,32 mov lowc,al ;print msg4 mov ah,9h lea dx,msg4 int 21h ;print: lowercase(from upc), ", ", uppercase(from lowc), ", ", digit mov ah,2h mov dl,upc int 21h mov ah,9h lea dx,sep int 21h mov ah,2h mov dl,lowc int 21h mov ah,9h lea dx,sep int 21h mov ah,2h mov dl,numc int 21h ;exit mov ah,4ch int 21h main endp end main
Copy text
Download
<< Back to Home