0% found this document useful (0 votes)
34 views8 pages

LAB 8 Solution

The document describes a program that displays a string of characters on the screen by setting the cursor position and writing each character. It initializes registers, sets the display mode, then loops through the string writing each character, incrementing the column position and decrementing the counter until all characters are displayed.

Uploaded by

f20221197
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)
34 views8 pages

LAB 8 Solution

The document describes a program that displays a string of characters on the screen by setting the cursor position and writing each character. It initializes registers, sets the display mode, then loops through the string writing each character, incrementing the column position and decrementing the counter until all characters are displayed.

Uploaded by

f20221197
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/ 8

.

model tiny
.data
inp1 db 'Mritunjay$' ; The name with a '$' terminator
colmstr db 4Eh ; Starting from column 78 (4Eh in hex is 78 in decimal)
cnt db 09h ; The length of the name (9 characters)

.code
.startup

; Set display mode to 80x25 text mode


Mov AH,00h
Mov AL,03h
INT 10h

; Initialize the registers


lea si, inp1 ; Load the address of the first character of the name
mov cl, [cnt] ; Load the length of the name into CL
mov dl, [colmstr] ; Load the starting column into DL
mov dh, 24 ; Set the starting row to the bottom of the screen

next_char:
; Set cursor position
mov ah, 02h
mov bh, 00h ; Page number
INT 10h ; Set cursor position

; Write character at cursor position


mov ah, 0Eh
mov al, [si] ; Get character from string
INT 10h ; Write character

; Move to the next character and update column and row


inc si ; Move to next character in the string
dec dl ; Move cursor left to next column
dec dh ; Move cursor up to next row

; Check if we've printed all characters


dec cl ; Decrement character count
jnz next_char ; If not zero, loop to print next character

; End of program, return to DOS


mov ah, 4ch
int 21h

.exit
end
.model tiny ; Set memory model to tiny (code and data in one segment)
.386 ; Target 80386 processor

.data ; Data segment


inp1 db 'Mritunjay' ; Define a byte array 'inp1' containing the input string
'MyName'
colmstr dw ? ; Define a word 'colmstr' to store the column position of the next
character
cnt db 0Ah ; Define a byte 'cnt' containing the length of the input string (6
characters)

.code ; Code segment


.startup ; Executable code starts here
; SET DISPLAY MODE
; Set video mode to 80x25 text, 16 colors
MOV AH, 00H
MOV AL, 03H
INT 10H

LEA SI, inp1


LEA DI, cnt
MOV CH, 00h
MOV CL, [DI]
MOV colmstr, 0Ah ; Set initial column position to 20
LEA DI, colmstr

; WRITING CHAR
WRITE1:
PUSH CX ; Save count value on the stack

; SETTING CURSOR POS


; Set the cursor position to row 20 and column specified by colmstr
MOV AH, 02H
MOV DH, [DI]
DEC DH
MOV DL, [DI]
DEC DL
MOV BH, 00
INT 10H

; Write a single character with custom vertical spacing


MOV AH, 09H
MOV AL, [SI] ; Load character from input string
MOV BH, 00
MOV BL, 00001111b ; Set custom vertical spacing
MOV CX, 01
INT 10H
POP CX ; Restore count value from the stack

; CHANGING VERTICES
; Increment the input string pointer, column position,
; and decrement the length counter
INC SI
INC WORD PTR[DI]
DEC CL
JNZ WRITE1 ; Repeat for all characters in the input string

END1:
MOV AH, 07H
INT 21h
CMP AL, "%"
JNZ END1

; TERMINATE PROGRAM
TERM:
MOV AH, 4CH ; Exit function
INT 21H

.exit ; Mark the end of the program


end ; End the program
.model tiny ; Specifies the memory model for the program

.data ; Declares the data segment


inp1 db 'ABCDEFGH' ; Declares a byte string containing 'ABCDEFGH'
colmstr dw ? ; Declares a word variable (2 bytes) 'colmstr'
initialized to 0
cnt db 08h ; Declares a byte variable 'cnt' initialized to 08h
(decimal 8)

.code ; Starts the code segment


.startup ; Entry point of the program

;display mode set


Mov AH,00h ; Sets AH register to 00h for function selection
Mov AL,03h ; Sets AL register to 03h for selecting text mode
INT 10h ; Calls BIOS interrupt to set the video mode

;initializing the registers


lea si,inp1 ; Loads the address of 'inp1' into SI register
lea di,cnt ; Loads the address of 'cnt' into DI register

mov ch,00h ; Clears the CH register


mov cl,[di] ; Loads the value pointed to by DI into CL register
mov colmstr,0h ; Clears the value stored at 'colmstr'
lea di,colmstr ; Loads the address of 'colmstr' into DI register

write1:
push cx ; Pushes the value of CX register onto the stack

mov ah,02h ; Sets AH register to 02h for setting cursor position


mov dh,[di] ; Loads the value at address DI into DH register (row
position)
mov dl,0h ; Sets column position to 0
mov bh,00 ; Sets page number to 0
INT 10h ; Calls BIOS interrupt to set cursor position

mov ah,09h ; Sets AH register to 09h for displaying a string


mov al,[si] ; Loads the character at address SI into AL register
mov bh,00 ; Sets page number to 0
mov bl,00001111b ; Sets display attribute to blinking white on black
mov cx,[di] ; Loads the value at address DI into CX register (string
length)
int 10h ; Calls BIOS interrupt to display the character

POP cx ; Pops the value from the stack into CX register

inc si ; Increments SI to point to the next character in 'inp1'


inc word ptr[DI] ; Increments the value pointed to by DI (increments
'colmstr')
dec cl ; Decrements the counter in CL
jnz write1 ; Jumps back to 'write1' label if counter is not zero

mov ah,4ch ; Sets AH register to 4Ch for terminating the program


int 21h ; Calls DOS interrupt to terminate the program
.exit ; Marks the end of the program
end ; End of program

You might also like