Re: Understanding code



Trev kirjoitti:

Hi all,
Sorry to burden this newsgroup, but I'd like to ask a few more
questions.
Part of what I am doing is learning by example, looking at other
assembly language routines
and trying to figure out what is going on, but the following two
snippets of code have me stumped.
They are connected with fopen() and fprintf() calls.
Can anyone help?

--------------------------------

mov edi, dword ptr ss:[ebp+c] ; [ebp+c] contains a pointer to a string
that gives file format information, such as "%s%s"
xor esi, esi
mov bl, byte ptr ds:[edi]
inc edi
test bl, bl
.
.
.
mov dword ptr ss:[ebp+c], edi
je LABEL
.
.
.
LABEL:
.
.
.
---------------------------------------

The above just gets a pointer to string, looking for terminating NULL,
and when found, saves pointer to string just after that found NULL
byte, and then jumps to LABEL...


The other bit of code is as follows:

mov edx, dword ptr ss:[esp+4] ; esp+4 is a pointer to the filename to
write to
test edx, edx
je short LABEL2

Get pointer to filename, if none provided go to LABEL2...



push edi
mov edi, edx
or ecx, ffffffff ; // ecx is "typically" 7f, and is an input
argument to this function
xor eax, eax
repne scas byte ptr es:[edi]
not ecx
dec ecx
pop edi
je LABEL2

Get length of filename, if length is zero go to LABEL2...


mov eax, dword ptr ss:[ebp+8] ; ebp+8 is the file access specifier,
such as "rw"
test eax, eax
je short LABEL2

Basically check if file access specifier is given, if not then go to
LABEL2...



LABEL2 :

-----------------------------

TIA

Trev

Hope this helps.

.



Relevant Pages

  • Understanding code
    ... test edx, edx ... je short LABEL2 ... push edi ... xor eax, eax ...
    (comp.lang.asm.x86)
  • Re: Fastcode Library Design
    ... cmp ecx, SMALLMOVESIZE ... lea edx, ... fild qword ptr [eax] ... mov ecx, ...
    (borland.public.delphi.language.basm)
  • Re: Time this code, please!
    ... xor(edx, edx); ... mov(d, eax); ... mov(width, ecx); ...
    (alt.lang.asm)
  • Re: Time this code, please!
    ... xor(edx, edx); ... mov(d, eax); ... mov(width, ecx); ...
    (alt.lang.asm)
  • Re: Kind of new: function implementation questions, MASM
    ... I don't yet understand the stack or the data segment. ... I think on entry to the function I should establish the stack frame. ... Then I use ds as the offset pointer to the data segment? ... mov eax, inputlength_s; move inputlength into eax, eax busy ...
    (comp.lang.asm.x86)