0% found this document useful (0 votes)
12 views

Lab 13 Task.docx

The document outlines two assembly programming tasks: the first task involves writing a program to input two strings and display their total character count, while the second task requires displaying a name with unique background and foreground colors for each character. It includes example code for both tasks, along with tips for user input and display functions. The code snippets demonstrate the use of DOS interrupts for string handling and character display.

Uploaded by

Meshaim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab 13 Task.docx

The document outlines two assembly programming tasks: the first task involves writing a program to input two strings and display their total character count, while the second task requires displaying a name with unique background and foreground colors for each character. It includes example code for both tasks, along with tips for user input and display functions. The code snippets demonstrate the use of DOS interrupts for string handling and character display.

Uploaded by

Meshaim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab#13 Task

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

Tips for user inputs and display


Mov ah, 09h is for displaying string, for which you send address of string in dx, like lea dx, str.
Mov ah, 02h is for displaying character, for which you don’t need to send address of string in dx.
Mov ah, 01h is for taking character input, you get input in al.
Mov ah, 0Ah is for taking string input, you get input in 3rd byte of mentioned array.

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

; Prompt for first string


lea dx, prompt1
mov ah, 09h
int 21h
lea dx, string1
call get_string

; Prompt for second string


lea dx, prompt2
mov ah, 09h
int 21h
lea dx, string2
call get_string

; Calculate total length


mov al, string1[1] ; Load length of first string (8-bit)
mov ah, 0 ; Clear upper byte
mov bx, ax ; Store first length in BX
mov al, string2[1] ; Load length of second string (8-bit)
add ax, bx ; Add both lengths
mov length, ax ; Store result in 'length'

; Display total characters


lea dx, resultMsg
mov ah, 09h
int 21h
mov ax, length
call print_number

; Exit program
mov ah, 4Ch
int 21h
main endp

; Function: Get string input from the user


get_string proc
mov ah, 0Ah ; DOS interrupt for buffered input
int 21h
ret
get_string endp

; Function: Print a number in AX


print_number proc
; Initialize
mov bx, 10 ; Divisor for decimal conversion
mov cx, 0 ; Counter for number of digits

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).

mov dx , offset msg


mov ah , 9h
int 21h
mov ah , 04ch
int 21h
end

You might also like