I'm trying to make a PROC out of two identical sequences of instructions
in order not to have duplicated code inside the program, but probably I need
to do something more than simply CALLing the sequence:
; -------------------------------------------------------------------------
; Fill the buffer with a box of 80 characters starting at line requested
; till the number of line passed as II parameter
;--------------------------------------------------------------------------
BuildBox PROC Row1:DWORD, Row2:DWORD
mov eax, Row1
sub eax, 1
imul eax, 320
mov edx, eax
lea eax, ConsoleScreen
add eax, edx
movzx ebx, byte ptr [TopLeft]
mov byte ptr [eax],bl
CALL BoxLine
COMMENT % ------------------------------------------
add eax, Four
mov ecx, LenBoxLine
movzx ebx, byte ptr [HorizLine]
FillBoxLine1:
mov byte ptr [eax], bl
add eax, Four
dec ecx
jnz FillBoxLine1
% --------------------------------------------------
movzx ebx, byte ptr [TopRight]
mov byte ptr [eax], bl
add eax, Four
mov ecx, Row2
sub ecx, Row1
dec ecx
movzx ebx, byte ptr [VerticLine]
FillBorder:
mov byte ptr [eax], bl
add eax, Four
mov edx, Four
imul edx, LenBoxLine
add eax, edx
mov byte ptr [eax], bl
add eax, Four
dec ecx
jnz FillBorder
movzx ebx,byte ptr [BottomLeft]
mov byte ptr [eax], bl
CALL BoxLine
COMMENT % ------------------------------------
add eax, Four
mov ecx, LenBoxLine
movzx ebx, byte ptr [HorizLine]
FillBoxLine2:
mov byte ptr [eax], bl
add eax, Four
dec ecx
jnz FillBoxLine2
% --------------------------------------------
movzx ebx, byte ptr [BottomRight]
mov byte ptr [eax], bl
ret
BuildBox ENDP
; -------------------------------------------------------------------------
; Writes the horizontal line of the Box
;--------------------------------------------------------------------------
BoxLine PROC
add eax, Four
mov ecx, LenBoxLine
movzx ebx, byte ptr [HorizLine]
FillBoxLine:
mov byte ptr [eax], bl
add eax, Four
LOOP FillBoxLine
ret ; <================= This was missing :-)
BoxLine ENDP
What did I miss?
Thanks
Frank
Oh my God!!! the RET again.
:red
Solved
The strange thing is the size is always 3.584 bytes.
I've to see a real change into the size of the program yet. ::)
I don't think that a CALL BoxLine takes the same size
than the sequence:
add eax, Four
mov ecx, LenBoxLine
movzx ebx, byte ptr [HorizLine]
FillBoxLine:
mov byte ptr [eax], bl
add eax, Four
LOOP FillBoxLine
Including the RET mnemonic. ::)
A small change in code will not normally lead to any change in the size of the program since space is allocated in sections. Your savings probably just left a bit of the last section blank but did not do anything to reduce the program size.
Edgar
Quote from: donkey on September 12, 2010, 07:44:02 PM
A small change in code will not normally lead to any change in the size of the program since space is allocated in sections. Your savings probably just left a bit of the last section blank but did not do anything to reduce the program size.
Edgar
Thanks Edgar.
I hope the left blanks will be used when I'll add some new code. :U