News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Drawing a basic box

Started by alec_tronn, October 30, 2007, 10:46:57 PM

Previous topic - Next topic

alec_tronn

The assignment is to make a program that draws a box with the coordinates in the format "Coords BYTE #,#,#,#"

It looks like I've done everything right, but when I run it it gives me a box with the cursor rapidly moving around the boarder, and I don't think thats whats supposed to happen.

Irvine32.inc is a textbook specific package that has a few useful procs in it, if you need me to I'll paste all of them here.


TITLE Box Program (Makeabox.asm)

;This program takes the coords as the max and min x,y values and
;makes a box out of them
;CS 250
INCLUDE Irvine32.inc


.data
Coords     BYTE 10,5,20,50
UL         BYTE 0DAh
UR         BYTE 0BFh
LL         BYTE 0C0h
LR         BYTE 0D9h
HL         BYTE 0C4h
VL         BYTE 0B3h

.code

draw_Corners PROC

mov dl, [Coords]
mov dh, [Coords+1]

call gotoxy

mov al, UL
call writechar



mov dl, [Coords+2]
mov dh, [Coords+1]

call gotoxy

mov al, UR
call writechar

mov dl, [Coords+2]
mov dh, [Coords+3]

call gotoxy

mov al, LR
call writechar


mov dl, [Coords]
mov dh, [Coords + 3]

mov al, LL

call gotoxy
Call Writechar

draw_Corners ENDP






draw_Horizontal Proc


mov dl, [Coords]
mov dh, [Coords + 1]
draw_Top:

inc dl

cmp dl, [Coords + 2]
JE bottom
mov al, HL
call gotoxy
call writechar
jmp draw_Top


bottom:
mov dl, [Coords]
mov dh, [Coords + 3]

draw_Bottom:
inc dl

cmp dl, [Coords + 2]
JE finish2
mov al, HL
call gotoxy
call writechar
jmp draw_Bottom




finish2:

draw_Horizontal ENDP



draw_Vertical Proc


mov dl, [Coords]
mov dh, [Coords + 1]
draw_Left:

inc dh

cmp dh, [Coords + 3]
JE bottom
mov al, VL
call gotoxy
call writechar
jmp draw_Left


bottom:
mov dl, [Coords + 2]
mov dh, [Coords + 1]

draw_Right:
inc dh

cmp dh, [Coords + 3]
JE finish2
mov al, VL
call gotoxy
call writechar
jmp draw_Right


finish2:

draw_Vertical ENDP



main PROC


mov al, green
call settextcolor

Call draw_Corners
Call Draw_Horizontal
Call Draw_Vertical



exit
main ENDP
END main



Any help, hints, comments, and criticisms are welcome. Thanks a lot!

Code tags added.

MichaelW

Your code as posted will not assemble. You need to add an include statement for smallwin.inc above the include statement for irvine32.inc. The main problem with the code is that the procedures lack a ret instruction at the end. When draw_Corners is called and execution reaches the end of the procedure, instead of returning to the Call Draw_Horizontal statement execution continues into the draw_Horizontal procedure, and so on down until it reaches the Call draw_Corners statement, and the whole things repeats. Two smaller problems are that the code is leaving the text cursor in a position that causes the system to overwrite the bottom of the box, and that the code is not restoring the original text color.

Also, if you would place your code between code tags, like this, but without the internal spaces:
[ c o d e ]
[ / c o d e ]
The formatting would be preserved and the code would be easier to read.
eschew obfuscation

askm

Sorry I didnt post sooner...

I spent a few minutes with this...last night.

I commented out lines 35,36 of the draw_Corners PROC... for one.

Maybe the returns will help.

It is a start to drawing a rectangle.

You could not hope to hold the ghosts and goblins inside it.

askm

alec_tronn

I put the returns in and everything worked great. I don't think I needed the include statement for smallwin.inc because I think it's probably already included in the Irvine16.inc (the textbook include file).

I'm not sure why I need to comment out 35 and 36... ??? My editor doesn't number them but I counted down and don't see anything wrong.

Thanks for the help! It looks like everything works nicely now. Any other help or criticisms would be appreciated, I'm really new at this so sorry if my code doesn't seem the most readable or reasonable.

MichaelW

QuoteI don't think I needed the include statement for smallwin.inc because I think it's probably already included in the Irvine16.inc (the textbook include file).
I think you mean Irvine32.inc, but you are right about the include statement for smallwin.inc. I recall now that I had commented the statement out as part of an experiment, and then forgot to change it back when I finished.
eschew obfuscation