The book I'm reading says one comment per a line so thats why theres comments all over the place. This was probably the most time consuming thing for the most simple output I've ever done in my life, and I must say, it feels good :O Anyways I'm going to be learning a lot more about the stack soon, so that should make these 112 lines into 70 or 80 lines. I'm probably going to end-up rebuilding the whole bloody thing, but still, it was fun to make.
Code:
[BITS 16] ; Set 16 bit code generation
SEGMENT junk ; Segment containing code
..start:
; linker where the code segment begins.
mov ax,data ; Move segment address of data segment into AX
mov ds,ax ; Copy address from AX into DS
mov ax,stack ; Move segment address of stack segment into AX
mov ss,ax ; Copy address from AX into SS
mov sp,stacktop ; Point SP to the top of the stack
call createBox ; Call createBox
jmp quit
;+----------------------+
;| Functions +
;+----------------------+
createBox:
mov cx,010H ; move 10h to CX register
call ?drawTop ; call draw top
mov bx,0Ah ; mov 0Ah to BX register
??createBoxLoop:
mov cx,010h ; move 010h to cx register
call ?drawSides ; Call drawSides
dec bx ; decrement bx register by one
call ?eof ; call eof
cmp bx,0h ; Compare BX,0
jne ??createBoxLoop ; is CF(Carry Flag) set?
mov cx,010h ; move CX Register to 010h
call ?drawTop ; call draw top
ret ; return
;+---------------------+
;| Sub-Calls |
;+---------------------+
;DRAW TOP FUNCTIONS
?drawTop:
mov ah,09h ; The service we want to call
mov dx,drawChar ; THe message we want to draw
??drawTopLoop: ; define loop label
INT 21h ; call service from DOS
dec cx ; decrease cx register by one
cmp cx,0h ; compare CX and 0
jne ??drawTopLoop ; if CX != 0h then hump do !draw
call ?eof ; call eof
ret ; return
;EOF Functions, outputs ASCII 13 to the console\End of line
?eof:
mov ah,09h ; Select service to call from DOS
mov dx,eofChar ; mov dx register to EOF char
int 21h ; Call selected service
ret ; return
;DRAW SIDES FUNCTIONS
?drawSides:
mov ah,09h ; the service within dos we want to call;
mov dx,drawChar ; Move dx register to addresses of drawChar
int 21h ; call selected service
mov dx,fillChar ; move dx register to the address of fillChar
??drawSideLoop:
int 21h ; Call selected service
dec cx ; decrease cx
cmp cx,2h ; Compare CX and 2h
jne ??drawSideLoop ; is CF set?
mov dx,drawChar ; mov dx register to the address of drawCharacter
int 21h ; call selected service
ret ; return
;+---------------------+
;| Jmp to |
;+---------------------+
quit:
mov ax, 04C00H ; select service
int 21H ; Call selected service from DOS
SEGMENT data ; Segment containing initialized data
drawChar db "+$"
fillChar db " $"
eofChar db 10,"$"
SEGMENT stack stack
resb 64
stacktop: