Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

.

model tiny
.data
rowstr dw ? ; Starting row position for painting
rowend dw ? ; Ending row position for painting
colmstr dw ? ; Starting column position for painting
colmend dw ? ; Ending column position for painting
cnt db 26 ; Counter for number of iterations
color db ? ; Variable to store color information

.code
.startup
; set graphics video mode
MOV AH, 00h ; Set AH register to 00h (Function to set video mode)
MOV AL, 12h ; Set AL register to 12h (Graphics mode)
INT 10h ; Call BIOS interrupt to set video mode

; parameters init
MOV rowstr, 0 ; Initialize starting row position to 0
MOV rowend, 20 ; Initialize ending row position to 20
MOV colmstr, 0 ; Initialize starting column position to 0
MOV colmend, 640 ; Initialize ending column position to 640
MOV color, 010b ; Initialize color to green (00001000b)

PAINT1:
MOV SI, rowstr ; Move starting row position to SI register
COLM1:
MOV CX, colmend ; Move ending column position to CX register
ROW1:
DEC CX ; Decrement CX (Column Counter)
MOV DI, CX ; Move CX to DI register
PUSH CX ; Push CX onto stack to preserve its value
MOV AH, 0Ch ; Set AH register to 0Ch (Function to set pixel)
MOV AL, color ; Set AL register to the value of color
MOV CX, DI ; Move DI (current column) to CX (for X-coordinate)
MOV DX, SI ; Move SI (current row) to DX (for Y-coordinate)
INT 10h ; Call BIOS interrupt to set pixel color
POP CX ; Restore the original value of CX from stack
CMP CX, colmstr ; Compare CX (current column) with starting column
JNZ ROW1 ; If not equal, repeat the loop for rows
INC SI ; Increment SI (row position)
MOV AX, rowend ; Move ending row position to AX register
CMP SI, AX ; Compare SI (current row) with ending row position
JNZ COLM1 ; If not equal, repeat the loop for columns
LEA SI, cnt ; Load effective address of cnt into SI
DEC BYTE PTR[SI] ; Decrement the value at the memory location pointed by SI
CMP cnt, 00 ; Compare cnt with zero
JZ TERM ; If zero, jump to termination section
MOV AL, cnt ; Move cnt to AL register
TEST AL, 01 ; Test the least significant bit of AL
JZ SETGREEN ; If zero, jump to SETGREEN to set color to green
MOV color, 101b ; Set color to magenta (00001001b)
JMP NEXT ; Jump to NEXT section
SETGREEN:
MOV color, 010b ; Set color to green (00001000b)
NEXT:
LEA SI, rowstr ; Load effective address of rowstr into SI
ADD WORD PTR[SI], 20 ; Add 20 to the value at the memory location pointed by SI
LEA SI, rowend ; Load effective address of rowend into SI
ADD WORD PTR[SI], 20 ; Add 20 to the value at the memory location pointed by SI
JMP PAINT1 ; Jump to PAINT1 to repaint

TERM:
MOV AH, 07h ; Set AH register to 07h (Function to output character to
stdout)
X1: INT 21h ; Call DOS interrupt to output character
CMP AL, '%' ; Compare AL (character) with '%'
JNZ X1 ; If not equal, repeat the loop
.exit
end
.model tiny
.data
rowstr dw ? ; Start row for painting
rowend dw ? ; End row for painting
colmstr dw ? ; Start column for painting
colmend dw ? ; End column for painting
cnt db 26 ; Counter for painting iterations
color db ? ; Color for painting
fname db 'lab1.txt', 0 ; File name to open
handle dw ? ; File handle
string db 12 dup('$') ; String to store data read from file
flag db 00 ; Flag indicating equality of input character and 12th byte
of the file (0 - equal; 1 - not equal)

.code
.startup

; Open a file (lab1.txt) for reading


MOV AH, 3Dh ; DOS function to open file
MOV AL, 00h ; Open for reading
LEA DX, fname ; Load file name address into DX
INT 21h ; Call DOS interrupt
MOV handle, AX ; Store file handle

; Read data from the file


MOV AH, 3Fh ; DOS function to read from file
MOV BX, handle ; Load file handle into BX
MOV CX, 12 ; Number of bytes to read
LEA DX, string ; Load address of string buffer
INT 21h ; Call DOS interrupt to read from file

; Close the file


MOV AH, 3Eh ; DOS function to close file
INT 21h ; Call DOS interrupt

; Point SI to 12th byte of the string


LEA SI, string ; Load address of string into SI
ADD SI, 11 ; Move SI to the 12th byte of the string

; Input a character from the user


MOV AH, 08h ; DOS function to read a character with no echo
INT 21h ; Call DOS interrupt

; Compare input character with 12th byte of the file


MOV AH, [SI] ; Move 12th byte of the file into AH
CMP AH, AL ; Compare input character with AH
JZ SETGRMODE ; Jump to set graphics mode if equal
MOV flag, 01 ; Set flag to 01 if not equal
MOV cnt, 27 ; Set count to 27 if not equal, ensuring an odd value

SETGRMODE: ; Set graphics video mode


MOV AH, 00h ; Set video mode function
MOV AL, 12h ; Graphics video mode (640x480, 16 colors)
INT 10h ; Call BIOS interrupt
; Initialize parameters
MOV rowstr, 0 ; Set starting row for painting
MOV rowend, 20 ; Set ending row for painting
MOV colmstr, 0 ; Set starting column for painting
MOV colmend, 640 ; Set ending column for painting
CMP flag, 00 ; Compare flag with 00
JNZ NOTEQ ; Jump to handle not equal case

; Set color to green if characters are equal


MOV color, 010b ; Green color
JMP PAINT1 ; Jump to start painting

NOTEQ: ; Set color to magenta if characters are not equal


MOV color, 101b ; Magenta color

PAINT1: ; Start painting loop


MOV SI, rowstr ; Load starting row into SI
COLM1: ; Column loop
MOV CX, colmend ; Load ending column into CX
ROW1: DEC CX ; Decrement CX for painting loop
MOV DI, CX ; Move column index into DI
PUSH CX ; Preserve CX
MOV AH, 0Ch ; Plot pixel function
MOV AL, color ; Set color
MOV CX, DI ; Load column index into CX
MOV DX, SI ; Load row index into DX
INT 10h ; Call BIOS interrupt
POP CX ; Restore CX
CMP CX, colmstr ; Compare CX with starting column
JNZ ROW1 ; Jump if not equal
INC SI ; Increment row index
MOV AX, rowend ; Load ending row into AX
CMP SI, AX ; Compare SI with ending row
JNZ COLM1 ; Jump if not equal

DEC cnt ; Decrement count


CMP cnt, 00 ; Compare count with 0
JZ TERM ; Jump to termination if count is 0

MOV AL, cnt ; Move count into AL


TEST AL, 01 ; Test if count is odd
JZ SETGREEN ; Jump to set color to green if count is even
MOV color, 101b ; Set color to magenta if count is odd
JMP NEXT ; Jump to NEXT
SETGREEN: ; Set color to green
MOV color, 010b ; Green color

NEXT: ; Move to next set of rows


LEA SI, rowstr ; Load address of starting row
ADD WORD PTR[SI], 20 ; Move to next set of rows
LEA SI, rowend ; Load address of ending row
ADD WORD PTR[SI], 20 ; Move to next set of rows
JMP PAINT1 ; Jump to paint next set of rows

TERM: ; Terminate program


MOV AH, 07h ; DOS function to beep
X1: INT 21h ; Call DOS interrupt
CMP AL, '%' ; Compare AL with '%'
JNZ X1 ; Jump if not equal

.exit
end

You might also like