Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views7 pages

Coa FinalAssignment

The document contains two assembly language programs. The first program manipulates and displays the values of registers AX, BX, CX, and SP in hexadecimal format. The second program reads a string from user input, reverses it, and displays the reversed string.

Uploaded by

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

Coa FinalAssignment

The document contains two assembly language programs. The first program manipulates and displays the values of registers AX, BX, CX, and SP in hexadecimal format. The second program reads a string from user input, reverses it, and displays the reversed string.

Uploaded by

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

Task2:

CODE:
.model small
.stack 100h
.data
msgAX db "Final AX: $"
msgBX db "Final BX: $"
msgCX db "Final CX: $"
msgSP db "Final SP: $"
newline db 0Dh, 0Ah, "$"
.code
main:
mov ax, @data
mov ds, ax
mov ax, 1234h
mov bx, 5678h
mov cx, 9abch
mov sp, 0100h
push ax
push bx
xchg ax, cx
pop cx
push ax
pop bx
lea dx, newline
mov ah, 09h
int 21h
lea dx, msgAX
mov ah, 09h
int 21h
mov dx, ax
call print_hex

lea dx, newline


mov ah, 09h
int 21h
lea dx, msgBX
mov ah, 09h
int 21h
mov dx, bx
call print_hex

lea dx, newline


mov ah, 09h
int 21h
lea dx, msgCX
mov ah, 09h
int 21h
mov dx, cx
call print_hex

lea dx, newline


mov ah, 09h
int 21h
lea dx, msgSP
mov ah, 09h
int 21h
mov dx, sp
call print_hex

mov ax, 4C00h


int 21h

print_hex proc
push ax
push bx
push cx

mov cx, 4
print_next_digit:
rol dx, 4
mov al, dl
and al, 0Fh
add al, '0'
cmp al, '9'
jbe print
add al, 7
print:
mov dl, al
mov ah, 02h
int 21h
loop print_next_digit

pop cx
pop bx
pop ax
ret
print_hex endp

end main

Output:
Task4:

.model small
.stack 100h
.data
input_msg db 'Enter a string: $'
output_msg db 0Dh, 0Ah, 'Reversed string: $'
input_str db 50 dup('$')
newline db 0Dh, 0Ah, '$'
.code
main:
mov ax, @data
mov ds, ax
mov es, ax

lea dx, input_msg


mov ah, 09h
int 21h

lea si, input_str


mov cx, 0

read_loop:
mov ah, 01h
int 21h
cmp al, 0Dh
je reverse
mov [si], al
inc si
inc cx
jmp read_loop

reverse:
mov byte ptr [si], '$'
lea dx, output_msg
mov ah, 09h
int 21h

lea si, input_str


mov bx, cx
push_chars:
cmp cx, 0
je pop_chars
mov al, [si]
push ax
inc si
dec cx
jmp push_chars

pop_chars:
cmp bx, 0
je done
pop dx
mov ah, 02h
mov dl, dl
int 21h
dec bx
jmp pop_chars
done:
lea dx, newline
mov ah, 09h
int 21h
mov ax, 4C00h
int 21h
end main

Output:

You might also like