[go: up one dir, main page]

0% found this document useful (0 votes)
62 views14 pages

COAL

This document contains solutions to programming questions in assembly language. It includes code snippets for reading hexadecimal digits from user input and converting them to decimal, summing binary numbers, and other basic operations. The code demonstrates using loops, conditional jumps, bitwise operations, and input/output functions to solve these problems.

Uploaded by

Ali Hassan
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)
62 views14 pages

COAL

This document contains solutions to programming questions in assembly language. It includes code snippets for reading hexadecimal digits from user input and converting them to decimal, summing binary numbers, and other basic operations. The code demonstrates using loops, conditional jumps, bitwise operations, and input/output functions to solve these problems.

Uploaded by

Ali Hassan
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/ 14

QUESTION 8:

SOL:.MODEL SMALL
.STACK 100H

.DATA
PROMPT_1 DB 'Enter the first capital letter : $'
PROMPT_2 DB 'Enter the second capital letter : $'
PROMPT_3 DB 'The given capital letters in alphabetical order are : $'
NEXT_LINE DB 0DH,0AH,"$"

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AH, 2
MOV DL, "?"
INT 21H

MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, PROMPT_1


INT 21H

MOV AH, 1
INT 21H

MOV BL, AL

MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, PROMPT_2


INT 21H

MOV AH, 1
INT 21H

MOV BH, AL
MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, PROMPT_3


INT 21H

MOV AH, 2

CMP BL, BH

JAE @GREATER
MOV DL, BL
INT 21H

MOV DL, BH
INT 21H

JMP @END

@GREATER:
MOV DL, BH
INT 21H

MOV DL, BL
INT 21H

@END:

MOV AH, 4CH


INT 21H
MAIN ENDP
END MAIN
QUESTION 9:
SOL:.model small
.stack 100h
.data

.code

mov cx,127
mov bl,0

print:

mov ah,2
inc cx
cmp cx,255
ja exit
mov dx,cx
int 21h
mov dx,32d
int 21h
jmp go
go:

inc bl
cmp bl,10
je nl
jmp print

nl:

mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov bl,0
jmp print

exit:
QUESTION 10:
SOL: .MODEL SMALL
.STACK 100H

.DATA
PROMPT DB 'Enter a HEX digit : $'
DECIMAL DB 'The equivalent Decimal digit is : $'
CONTINUE DB 'Do you want to do it again : $'
ILLEGAL DB 'Illegal Character - Enter 0..9 or A..F : $'
TERMINATE DB 'You failed to enter a HEX DIGIT, press any key to exit. $'
NEXT_LINE DB 0DH,0AH,"$"

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

@START_1:
MOV AH, 9
LEA DX, PROMPT
INT 21H

@START_2:
MOV AH, 1
INT 21H

MOV BL, AL

CMP BL, "A"


JB @SINGAL_DIGIT

CMP BL, "F"


JA @ILLEGAL_CHARACTER

JMP @GREATER_THAN_NINE

@SINGAL_DIGIT:
CMP BL, "0"
JB @ILLEGAL_CHARACTER

CMP BL, "9"


JA @ILLEGAL_CHARACTER

JMP @LESS_THAN_TEN
@ILLEGAL_CHARACTER:
INC CL

CMP CL, 3
JE @TERMINATE

MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, ILLEGAL


INT 21H

JMP @START_2

@LESS_THAN_TEN:
MOV CL, 0
MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, DECIMAL


INT 21H

MOV AH, 2
MOV DL, BL
INT 21H

JMP @CONTINUE

@GREATER_THAN_NINE:
MOV CL, 0
MOV AH, 9

LEA DX, NEXT_LINE


INT 21H

LEA DX, DECIMAL


INT 21H

MOV AH, 2
MOV DL, 31H
INT 21H

SUB BL, 11H

MOV DL, BL
INT 21H

@CONTINUE:
MOV AH, 9

LEA DX, NEXT_LINE


INT 21H
INT 21H

LEA DX, CONTINUE


INT 21H

MOV AH, 1
INT 21H

CMP AL, "y"


JE @JUMP

CMP AL, "Y"


JE @JUMP

JMP @END

@JUMP:
LEA DX, NEXT_LINE
MOV AH, 9
INT 21H
INT 21H

JMP @START_1

@TERMINATE:
MOV AH, 9

LEA DX, NEXT_LINE


INT 21H
INT 21H
LEA DX, TERMINATE
INT 21H

MOV AH, 1
INT 21H

@END:

MOV AH, 4CH


INT 21H
MAIN ENDP
END MAIN
QUESTION 11:
SOL:.model small
.stack 100h
.data

msg1 db 'Type a binary number upto 16 digits:$'


msg2 db 10,13,'in hex it is:$'

.code

main proc
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,9
int 21h

xor bx,bx
mov ah,1
int 21h

input:
cmp al,0dh
je exit

and al,0fh
shl bx,1
or bl,al

int 21h
jmp input

exit:
lea dx,msg2
mov ah,9
int 21h

mov cx,4

convert:
mov dl,bh
shr dl,1
shr dl,1
shr dl,1
shr dl,1

cmp dl,9

jbe num
add dl,55d
jmp display

num:
add dl,30h

display:
mov ah,2
int 21h

rcl bx,1
rcl bx,1
rcl bx,1
rcl bx,1

loop convert

main endp
end main
QUESTION 12:
SOL:.model small
.stack 100h

.data

msg1 db 10,13,'Type a binary number upto 8 digits:$'


msg2 db 10,13,'The binary sum is:$'

.code

main proc
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,9
int 21h

mov ah,1
int 21h

xor bx,bx
mov cx,8
input1:
mov ah,1
int 21h
cmp al,0dh
je break

and al,0fh
shl bl,1

or bl,al

loop input1

break:
lea dx,msg1
mov ah,9
int 21h

mov cx,8

input2:
mov ah,1
int 21h

cmp al,0dh
je break2

and al,0fh
shl bh,1

or bh,al

loop input2

break2:
lea dx,msg2
mov ah,9
int 21h

sum:
add bl,bh
jnc zero
mov dl,31h
mov ah,2
int 21h

zero:
mov dl,30h
mov cx,8

print:
shl bl,1
jnc z
mov dl,31h
jmp display

z:
mov dl,30h

display:

mov ah,2
int 21h

loop print

main endp
end main

You might also like