News:

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

Something is missing

Started by frktons, September 12, 2010, 06:40:53 PM

Previous topic - Next topic

frktons

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

Mind is like a parachute. You know what to do in order to use it :-)

frktons

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.  ::)
Mind is like a parachute. You know what to do in order to use it :-)

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

frktons

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
Mind is like a parachute. You know what to do in order to use it :-)