Lab 13 Task.docx
Lab 13 Task.docx
1. Example # 01 contains code for Task1 “Write an assembly program to Enter two string
and then display Number of characters entered by you in next line and display the strings
you entered.”
2. Write a simple assembly language program to Display your name, each character should
have a unique background and foreground color. (Utilize Attributebyte). Sample code is
given in Example # 02
Example # 01:
.model small
.stack 100h
.data
prompt1 db 'Enter first string: $'
prompt2 db 0Dh, 0Ah, 'Enter second string: $'
resultMsg db 0Dh, 0Ah, 'Total characters entered: $'
string1 db 50, 0, 50 dup(0) ; First byte = max size, second byte = length, rest = buffer (data)
string2 db 50, 0, 50 dup(0) ; Same structure for second string
length dw 0 ; To store total length
.code
main proc
mov ax, @data
mov ds, ax
; Exit program
mov ah, 4Ch
int 21h
main endp
cmp ax, 0
jne convert_to_decimal
; If AX is zero, print '0'
mov dl, '0'
mov ah, 02h
int 21h
jmp print_end
convert_to_decimal:
xor dx, dx ; Clear DX before division
convert_loop:
div bx ; Divide AX by BX, quotient in AX, remainder in DX
push dx ; Push remainder (digit) onto stack
inc cx ; Increment digit counter
cmp ax, 0
jne convert_loop ; Repeat until quotient is zero
print_digits:
pop dx ; Pop digit from stack
add dl, '0' ; Convert digit to ASCII
mov ah, 02h ; DOS interrupt to print a character
int 21h
loop print_digits ; Repeat for all digits
print_end:
ret
print_number endp
Example # 02:
.model small
.stack
.data
msg db "HELLO!!$"
.code
mov ax , @data
mov ds , ax
mov ax , 0B800h ; 0B800h is starting address of video memory in VGA text mode.
mov es , ax ; Now, program sets up ES register to point to video memory segment.
; The video memory is now accessible through ES segment register.
mov es:0 , 0100h ; MSD 0 represents black background, Lower MSD 1 represents blue
foreground.
; 00h represents a null character (not visible).
mov es:2 , 0200h ; MSD 0 represents black background, Lower MSD 2 represents green
foreground.
; 00h represents null character (not visible).
mov es:4 , 0e00h ; MSD 0 represents black background, Lower MSD e represents yellow
foreground.
; 00h represents null character (not visible).
mov es:6 , 1400h ; MSD 1 represents blue background, Lower MSD 4 represents red foreground.
; 00h represents null character (not visible).