0% found this document useful (0 votes)
23 views12 pages

SM Lab 2

The document contains 10 examples of assembly language code solutions. Each example solves a different programming problem related to input/output, comparison of values, and loops. The code examples demonstrate how to perform tasks like comparing numbers, displaying characters, counting inputs, and reading input until a blank is encountered.

Uploaded by

Saimun Mahumd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views12 pages

SM Lab 2

The document contains 10 examples of assembly language code solutions. Each example solves a different programming problem related to input/output, comparison of values, and loops. The code examples demonstrate how to perform tasks like comparing numbers, displaying characters, counting inputs, and reading input until a blank is encountered.

Uploaded by

Saimun Mahumd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Ex 6.1: Suppose AX and BX contain signed numbers.

Write some code


to put the biggest one in CX.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov cx,ax
int 21h
mov bx,ax
cmp cx,bx
jg lev1
jl lev2
lev1:
mov ah,2
mov dx,cx
int 21h
mov ah,4ch
int 21h
lev2:
mov ah,2
mov dx,bx
int 21h
mov ah,4ch
int 21h
main endp
end main

Ex6.2: Replace the number in AX by its absolute value.

Solution:
.model small
.stack 100h
.code
main proc
mov ax,-8
cmp ax,0
jge goto
neg ax
add ax,48
mov ah,2
mov dx,ax
int 21h
mov ah,4ch
int 21h
goto:
add ax,48
mov ah,2
mov dx,ax
int 21h
mov ah,4ch
int 21h
main endp
end main

Ex6.3: Suppose AL and BL contain extended ASCII characters.Display


the one comes first in the character sequence.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov bl,al
int 21h
mov bh,al
cmp bl,bh
jl goto
mov ah,2
mov dl,bh
int 21h
mov ah,4ch
int 21h
goto:
mov ah,2
mov dl,bl
int 21h
mov ah,4ch
int 21h
main endp
end main

Ex6.4: If AX contains a negative number , put -1 in BX ; if AX contains


0, put 0 in BX ; if AX contains a positive number , put 1 in BX.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov dx,ax
cmp dx,'0'
je goto
jl goto1
mov bx,1
mov ah,2
add bx,48
mov dx,bx
int 21h
mov ah,4ch
int 21h
goto:
mov bx,0
mov ah,2
add bx,48
mov dx,bx
int 21h
mov ah,4ch
int 21h
goto1:
mov bx,-1
mov ah,2
add bx,48
mov dx,bx
int 21h
mov ah,4ch
int 21h
main endp
end main
Ex6.5: If AL contains 1 or 3 , display “O” ;If AL contains 2 or 4 , display
“E”.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov dl,al
cmp dl,'1'
je print
cmp dl,'3'
je print
cmp dl,'2'
je print1
cmp dl,'4'
je print1
print:
mov ah,2
mov dl,'O'
int 21h
mov ah,4ch
int 21h
print1:
mov ah,2
mov dl,'E'
int 21h
mov ah,4ch
int 21h
main endp
end main

Ex6.6: Read a character, and if it’s an uppercase letter, display it.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov bl,al
cmp bl,'A'
jl exit
cmp bl,'Z'
jg exit
mov ah,2
mov dl,bl
int 21h
exit:
mov ah,4ch
int 21h
main endp
end main

Ex6.7: Read a character it it’s “y” or “Y” , display it ; otherwise,


terminate the program.

Solution:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
cmp al,'y'
je next
cmp al,'Y'
je next
jmp exit
next:
mov ah,2
mov dl,al
int 21h
exit:
mov ah,4ch
int 21h
main endp
end main

Ex6.8: Write a count-controlled loop to display a row of 80 stars

Solution:
.model small

.stack 100h

.code

main proc

mov cx,80

do:

mov ah,2

mov dx,'*'

int 21h
loop do

mov ah,4ch

int 21h

main endp

end main

Ex6.9: Write some code to count the number of characters in an input


line.

Solution:
.model small
.stack 100h
.code
main proc

mov bl,30h
label:
mov ah,1
int 21h
inc bl
cmp al,20h
je goto
jmp label
goto:
mov ah,2
sub bl,1
mov dl,bl
int 21h

mov ah,4ch
int 21h
main endp
end main

Ex6.10 : Write some code to read characters until a blank is read.

Solution:
.model small
.stack 100h
.code
main proc

mov bl,'0'
do:
mov ah,1
int 21h
mov dl,bl
cmp dl,' '
je goto
inc bl
loop do
goto:
mov ah,2
mov dl,bl
int 21h
mov ah,4ch
int 21h
main endp
end main

You might also like