News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

cmd_tail

Started by HSE, June 09, 2024, 08:03:22 AM

Previous topic - Next topic

HSE

Hi all!

I was thinking that cmd_tail function don't worked at all. I don't remember what test I made, but perhaps failed because almost nothing  :biggrin:

The function in SDK don't preserve registers:
Code ("Original cmd_tail.asm") Select
    mov rax, r14                        ; return output buffer in RAX
    ret
  zeroexit:
    mov rax, r14
    mov BYTE PTR [rax], 0              ; zero 1st byte of r14
    mov rax, r14                        ; return zeroed buffer in RAX
    RestoreRegs
    ret

That can be changed to:
Code ("Modification cmd_tail.asm") Select
    mov rax, r14                       
    jmp exit                            ; return output buffer in RAX
  zeroexit:
    mov rax, r14                        ; return zeroed buffer in RAX
    mov BYTE PTR [rax], 0              ; zero 1st byte of r14
  exit:
    RestoreRegs
    ret

And work pretty well  :thumbsup:

Regards, HSE.
Equations in Assembly: SmplMath

jj2007

The second line solves a serious problem with cmd_tail:
  lbl:
    call cmd_tail ; get commandline
    mov byte ptr [rax+r13], 0 ; put zero delimiter
    mov pFile, rax ; store rax in variable

Inter alia, the missing zero delimiter was the reason why the Project macros didn't work when teditor was invoked from the commandline with the filename as argument.

sinsi

    mov r12, rvcall(GetCommandLine)
    mov r13, len(r12)
    mov r14, alloc(r13)
Does len take into account the zero terminator?
Otherwise alloc would be one byte short (which would probably be swallowed by alignment, but...)

jj2007

The proper solution would clearly be to fix the library source, i.e. cmd_tail.asm

HSE

Quote from: sinsi on June 12, 2024, 12:01:27 AMDoes len take into account the zero terminator?

:thumbsup: Fantastic Sinsi. That it's the point.

Then must be:
    mov r12, rvcall(GetCommandLine)
    mov r13, len(r12)
    add r13, 1
    mov r14, alloc(r13)
Equations in Assembly: SmplMath