Yes I've searched through this forum, found all kinds of examples, I still do not feel comfortable enough to rip them for my own use until I understand what is going on.. below is what I've been working on so far.
I probably need the most help with the registers, for when I try to assemble this, I get a slap on the wrist.
Maybe I am missing the point with strings and the ecx register?
note: I'm not looking for a re-writing as much as I am looking for what I'm doing wrong, like trying to code in assembler ~:\
StrCat proc uses edi esi Dst:DWORD, ToAdd:DWORD
mov edi,
mov esi,
xor ecx,ecx
invoke StrLen,Dst
@loop:
add eax,ecx
lea , <===== error A2000: memory operand not allowed in context
inc ecx ;increment ecx
cmp esi,0 ;check for end of ToAdd
jne @loop
ret
StrCat endp
I probably need the most help with the registers, for when I try to assemble this, I get a slap on the wrist.
Maybe I am missing the point with strings and the ecx register?
note: I'm not looking for a re-writing as much as I am looking for what I'm doing wrong, like trying to code in assembler ~:\
StrCat proc uses edi esi Dst:DWORD, ToAdd:DWORD
mov edi,
mov esi,
xor ecx,ecx
invoke StrLen,Dst
@loop:
add eax,ecx
lea , <===== error A2000: memory operand not allowed in context
inc ecx ;increment ecx
cmp esi,0 ;check for end of ToAdd
jne @loop
ret
StrCat endp
lea can only be used with a register as a destination (the first operand). By dereferencing the value in edi+eax you are using a memory address ie if eax = 1 and edi = 2 you are actually using address 3 (edi+eax).
@loop:
add eax,ecx
mov edx,
mov , edx
;lea , <===== error A2000: memory operand not allowed in context
inc ecx ;increment ecx
cmp edx,0 ;check for end of ToAdd
jne @loop
You may want to take a look at C:\masm32\HELP\ASMINTRO.HLP, it covers some concepts of addressing modes and registers
add eax,ecx
mov edx,
mov , edx
;lea , <===== error A2000: memory operand not allowed in context
inc ecx ;increment ecx
cmp edx,0 ;check for end of ToAdd
jne @loop
You may want to take a look at C:\masm32\HELP\ASMINTRO.HLP, it covers some concepts of addressing modes and registers
Thanx Donkey, I looked at the help file and found an example to help me along. I modified it to this and it works as expected:
StrCat proc uses edi esi Dst:DWORD, ToAdd:DWORD
cld
mov edi, [Dst]
mov esi, [ToAdd]
xor ecx,ecx
invoke StrLen,Dst
add edi,eax
@loop:
lodsb ; load byte from source into AL and inc ESI
stosb ; write AL to dest and inc EDI
cmp al, 0 ; see if its an ascii zero
jne @loop ; read the next byte if its not
ret
StrCat endp
Pretty good. lodsb and stosb are very inefficient opcodes though, it would not be very optimized. You might also want to check the agner fog optimization file C:\masm32\HELP\Agner.hlp, generally you would use the lods/stos opcodes in conjunction with a REP.
i.e. on a 586
lodsb uses 5 clocks
stosb uses 5 clocks
total = 10 clocks
mov al, 1 clock
inc esi (paired)
mov , al 1 clock
inc edi (paired)
total = 2 clocks
pairing allows you to execute two instructions simultaneously in the two pipes.
i.e. on a 586
lodsb uses 5 clocks
stosb uses 5 clocks
total = 10 clocks
mov al, 1 clock
inc esi (paired)
mov , al 1 clock
inc edi (paired)
total = 2 clocks
pairing allows you to execute two instructions simultaneously in the two pipes.
I've got alot to learn.. thanks again.
Bah, it's not so bad, optimizing is fun but not really necessary in most cases. It is usually good to keep in mind ways to use faster instructions though. The most important thing in most programs isn't how fast it does the job but just that it does the job. After all spending 10 mins to optimize an algorithm that is only run once might only save you a few microseconds. But generally stuff like CatStr and such needs to be optimized as it is used alot. Have you checked the source code for MASM32 ? These functions are all in the library and the source is supplied in \masm32\masm32lib I think.