Reputation: 113
I try to change the string to the other one, but the output I get is broken.
How do I change string to the other one so it doesn't do this:
Intended output:
in rect
under line
out circ
Also, I do not know the purpose of "offset" in the code so it also can be the problem.
Also, I get some warnings when trying to assemble it and I don't know they mean:
The code:
.model small
.data
X db 0
Y db 0
var0 db 0
rect db "out rect",13,10,"$"
rect_plus db "in rect",13,10,"$"
line db "under line",13,10,"$"
line_plus db "above line",13,10,"$"
circ db "out circ",13,10,"$"
circ_plus db "in circ",13,10,"$"
.code
main:
mov ax, @data
mov ds, ax
jmp input
input:
...
jmp rect_check1
rect_check1:
...
jb rect_check2
jmp rect_print
rect_check2:
...
jb rect_change
jmp rect_print
rect_change:
lea bx, rect; <============== SOMETHING WRONG HERE
mov [bx], offset rect_plus; <=========================== OR HERE
jmp rect_print
rect_print:
mov dx, offset rect; <=========================== OR HERE
mov ah, 09h
int 21h
jmp line_check
line_check:
...
jb line_change
jmp line_print
line_change:
lea bx, line; <=========================== OR HERE
mov [bx], offset line_plus; <=========================== OR HERE
jmp line_print
line_print:
mov dx, offset line; <=========================== OR HERE
mov ah, 09h
int 21h
jmp circ_check
circ_check:
...
jb circ_change
jmp circ_print
circ_change:
lea bx, circ; <=========================== OR HERE
mov [bx], offset circ_plus; <=========================== OR HERE
jmp circ_print
circ_print:
mov dx, offset circ; <=========================== OR HERE
mov ah, 09h
int 21h
jmp quit
quit:
mov ax, 4c00h
int 21h
end main
Upvotes: 0
Views: 125
Reputation: 5775
rect_change:
lea bx, rect; <============== SOMETHING WRONG HERE
mov [bx], offset rect_plus; <=========================== OR HERE
jmp rect_print
Your logic is wrong here.
lea bx, rect
loads the offset of string "out rect",13,10,"$"
to register bx
. The offset in bx
is then 0003h. The next instruction tries to overwrite one or two bytes of memory at ds:bx
(the letters "o" or "ou") with offset of another string "in rect",13,10,"$"
(with binary number 000Eh) which makes no sense. As you didn't specify how many bytes you're going to overwrite, TASM gives you the Warning.
Restructuralize your spaghetti code and make your subprocedures callable (ending with ret
), for instance
line_print PROC ; Display the $-terminated string addressed with DS:DX.
mov ah, 09h
int 21h
ret
line_print ENDP
Then, whenever you want to display a string, load its offset to dx
and call the subprocedure:
mov dx,offset rect
call line_print
; check the rectangle
mov dx,offset rect_plus
call line_print
Upvotes: 2