Professional Documents
Culture Documents
Lab 9 Solution
Lab 9 Solution
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
.exit
end