Assembly_Lab_fianl (1)
Assembly_Lab_fianl (1)
/////////////////////////////////////////////////////////
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 0AH, 0DH, 'The numbers from 0 to 9 are: $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH, 09H
LEA DX, MSG
INT 21H
MOV CX, 10
MOV AL, '0'
PRINT_LOOP:
MOV AH, 02H
MOV DL, AL
INT 21H
INC AL
LOOP PRINT_LOOP
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////
Largest among 2 numbers
////////////////////////////////////////////////////////////////////////////////
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 0AH, 0DH, 'The smallest number is: '
MSG1 DB 0AH, 0DH, 'The largest number is: '
num1 db 1
num2 db 2
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
con1:
xchg al,bl
print:
end:
mov ah, 4ch ; Terminate program
int 21h
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////////
///
smallest middle largest
///////////////////////////////////////////////////////////////////////////////////
//
.MODEL SMALL
.STACK 100H
.DATA
num1 DB 3 ; Example single-digit numbers
num2 DB 5
num3 DB 2
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
done_swap:
; AL contains smallest, BL contains middle, CL contains largest
add al, '0' ; Convert AL to ASCII
mov dl, al ; Move the ASCII character to DL
mov ah, 2 ; DOS function to print character
int 21h ; Print the character
; Print the middle number
add bl, '0' ; Convert BL to ASCII
mov dl, bl ; Move the ASCII character to DL
mov ah, 2 ; DOS function to print character
int 21h ; Print the character
; Print the largest number
add cl, '0' ; Convert CL to ASCII
mov dl, cl ; Move the ASCII character to DL
mov ah, 2 ; DOS function to print character
int 21h ; Print the character
; Exit program
mov ah, 4ch
int 21h
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////////
//
integer to word
///////////////////////////////////////////////////////////////////////////////////
/
.MODEL SMALL
.STACK 100H
.DATA
msg DB 0AH, 0DH, 'Enter a single digit (0-9): $'
numbers DB
'Zero$','One$','Two$','Three$','Four$','Five$','Six$','Seven$','Eight$','Nine$'
.CODE
MAIN PROC
; Initialize data segment
mov ax, @data
mov ds, ax
exit:
; Exit program
mov ah, 4ch
int 21h
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////////
//////////
frequency of a digit
///////////////////////////////////////////////////////////////////////////////////
///////////
.model small
.stack 100h
.data
string db 'stresses$'
msg db 0ah,0dh,'The number of times ''s'' appeared is:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
lea si,string
mov cx,0
count:
mov al,[si]
cmp al,'$'
je done
cmp al,'s'
jne next
inc cx
next:
inc si
jmp count
done:
mov al,cl
add al,30h
mov ah,2
mov dl,al
int 21h
mov ah,4ch
int 21h
end main
////////////////////////////////////////////////////////////////////////////////
print the nth elemnt in a stack
//////////////////////////////////////////////////////////////////////////////////
.MODEL SMALL
.STACK 100H ; Define a stack segment with 256 bytes of space
.DATA
MSG DB 0AH, 0DH, 'The eighth element on the stack is: $'
NUMBERS DB 8, 7, 6, 5, 4, 3, 2, 1 ; Define 8 single-digit numbers
.CODE
MAIN PROC
MOV AX, @DATA ; Initialize data segment
MOV DS, AX
; Now the 8th element (first pushed number) is on top of the stack
POP AX ; Pop the 8th element into AX
ADD AL, '0' ; Convert the number to ASCII
MOV DL, AL
MOV AH, 2
INT 21H ; Print the character
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
; Exit program
mov ax, 4c00h
int 21h
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////////
//////////////////
dec to binary
///////////////////////////////////////////////////////////////////////////////////
/////////////////
.MODEL SMALL
.STACK 100H
.DATA
Num DB 8 ; Example decimal number to convert
binaryNum DB 8 DUP(0) ; Space for 8 bits binary result
msg DB 0AH, 0DH, 'Binary number is: $'
newline DB 0AH, 0DH, '$' ; Newline for printing
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
convert_loop:
; Check if AL is zero
test al, al
jz print_binary ; If zero, go to print
; Divide AL by 2
mov bl, 2 ; Divisor
xor ah, ah ; Clear AH
div bl ; AL = AL / 2, AH = AL % 2 (remainder)
print_binary:
dec di ; Adjust DI to the last digit index
print_loop:
mov al, binaryNum[di] ; Load binary digit
add al, '0' ; Convert to ASCII
mov dl, al ; Move to DL for printing
mov ah, 2 ; DOS function to print character
int 21h ; Print character
dec di ; Move to the previous bit
loop print_loop ; Repeat until all bits printed
; Print newline
mov ah, 9
lea dx, newline
int 21h
; Exit program
mov ax, 4c00h
int 21h
MAIN ENDP
END MAIN
///////////////////////////////////////////////////////////////////////////////////
//////////////////////
binary to dec
///////////////////////////////////////////////////////////////////////////////////
////////////////////