My program has 3 problems. First, I take two address and loop for each address.
I tried adding 01h to eax until it's greater than ebx. I tried adding 010h. I tried subtracting the two and then adding one. I either get 2 address (by adding the 010h), or a I many. Is there a way to just get the three?
The next problem is, I take a pushed address, like ebx, and I want the first 16 bytes. I take and push it for another proc, then I want the next byte. I tried adding 4 to eax, adding 1, and shifting right 4. Nothing works. It just crashes.
The last problem is very close to the second problem. Instead of push , I want to print it, but only if only certain characters. I take my variable used for ouput and lea into ecx. I want to compare the value at ebx and make sure it's a good character, then move it into the output variable. I have the ouput part working with another program, but not with this one. I can't test it with this one because I need to fix problem 2 before this would work. I still can't loop through ebx. The way the output thing works is, I mov al, then mov BYTE PTR , al. Then, I add 2 to output, so when it prints, there is a space between each character.
Anyone know what my looping problems are?
.DATA
temp BYTE "badaasdfasdf",0
temp2 BYTE "adaasdfasdfasd",0
temp3 BYTE "daadfasdfasdfas",0
.CODE
lea eax, temp
lea ebx, temp3
I tried adding 01h to eax until it's greater than ebx. I tried adding 010h. I tried subtracting the two and then adding one. I either get 2 address (by adding the 010h), or a I many. Is there a way to just get the three?
The next problem is, I take a pushed address, like ebx, and I want the first 16 bytes. I take and push it for another proc, then I want the next byte. I tried adding 4 to eax, adding 1, and shifting right 4. Nothing works. It just crashes.
The last problem is very close to the second problem. Instead of push , I want to print it, but only if only certain characters. I take my variable used for ouput and lea into ecx. I want to compare the value at ebx and make sure it's a good character, then move it into the output variable. I have the ouput part working with another program, but not with this one. I can't test it with this one because I need to fix problem 2 before this would work. I still can't loop through ebx. The way the output thing works is, I mov al, then mov BYTE PTR , al. Then, I add 2 to output, so when it prints, there is a space between each character.
Anyone know what my looping problems are?
Hopefully, I have made good assumptions about your goals. Please, provide more info if I'm too far off track...
1) There is no concept of FOR EACH in assembly - you have to construct it. This is one possible implementation using string pointers:
3) You should have this one solved now.
1) There is no concept of FOR EACH in assembly - you have to construct it. This is one possible implementation using string pointers:
.DATA
temp0 BYTE "badaasdfasdf",0
temp1 BYTE "adaasdfasdfasd",0
temp2 BYTE "daadfasdfasdfas",0
MyList \
DWORD OFFSET temp0
DWORD OFFSET temp1
DWORD OFFSET temp2
; DWORD OFFSET tempN ; as many as you want...
DWORD 0
.CODE
lea ebx, MyList
ForEach:
mov eax, [ebx]
add ebx, 4
test eax, eax
je Exit
.
. ; do the stuff with string in EAX
.
jmp ForEach
Exit:
2) Have to add 16 to EBX to get the bytes after the 16. Don't shift an address in a register - it has no meaning.
3) You should have this one solved now.
Thanks for the reply! The MyList thing works perfectly! I do have a question, though. What does test eax, eax do? They are equal, so wouldn't it always jump?
The adding 16 is a bit confusing. I added it and the loop worked, it printed out 16 numbers, but they weren't the right numbers.
With that, I take 'b' and push it into a convert-to-hex proc. I tested that proc several times, and it works. I only get the first number, or sometimes the first four numbers right in hex. The remaining 12 is usually 00 with some random stuff in the middle.
The second part should print out the characters themselves, but just the first 16. Adding 16 to it prints out everything.
I should get:
62 61 64 61 61 73 64 66 61 73 64 66 00 00 00 00 badaasdfasdf
00 00 00 00 can be anything, whatever is left in memory. If I had "1111111122222222333333334444444455555555" I should get:
31 31 31 31 31 31 31 31 32 32 32 32 32 32 32 32 1111111122222222
For my print loop, I mov 16 into ecx, print , add eax, 16, and then loop. That would prints:
31 33 35 61 66 20 00 00 00 00 00 00 00 03 00 00 111111112222222233333333444444445555555533333333444444445555555555555555asdfasdfasdfas
Hopefully that made it a little more clear. Maybe your code does do that, but my other code is what's messed up.
The adding 16 is a bit confusing. I added it and the loop worked, it printed out 16 numbers, but they weren't the right numbers.
.DATA
temp0 BYTE "badaasdfasdf",0
temp2 BYTE "adaasdfasdfasd",0
With that, I take 'b' and push it into a convert-to-hex proc. I tested that proc several times, and it works. I only get the first number, or sometimes the first four numbers right in hex. The remaining 12 is usually 00 with some random stuff in the middle.
The second part should print out the characters themselves, but just the first 16. Adding 16 to it prints out everything.
I should get:
62 61 64 61 61 73 64 66 61 73 64 66 00 00 00 00 badaasdfasdf
00 00 00 00 can be anything, whatever is left in memory. If I had "1111111122222222333333334444444455555555" I should get:
31 31 31 31 31 31 31 31 32 32 32 32 32 32 32 32 1111111122222222
For my print loop, I mov 16 into ecx, print , add eax, 16, and then loop. That would prints:
31 33 35 61 66 20 00 00 00 00 00 00 00 03 00 00 111111112222222233333333444444445555555533333333444444445555555555555555asdfasdfasdfas
Hopefully that made it a little more clear. Maybe your code does do that, but my other code is what's messed up.
TEST is exactly like AND - except the result is not kept. Basically, it is a quick way to test for zero because the processor can take advantage of the result not needing to be stored. ( :idea: Similarly, CMP is exactly like SUB.)
Yes, we are in agreement on the rest. Seeing a larger section of your code would be the only way to diagnose further.
Yes, we are in agreement on the rest. Seeing a larger section of your code would be the only way to diagnose further.
lineBuffer proc
push ebp ;saving ebp
mov ebp, esp ;copy stack pointer
pushad ;push registers
mov eax, [ebp+8] ;address
mov ebx, eax ;make copy
push eax ;push address
call hexDWPrint ;convert address to hex
mov ecx, 16 ;mov 16 into ecx for looping
theLoop: push [eax] ;this is 1 byte in the address pushed
call hexBPrint ;converts that byte to hex
goodchar: add eax, 16 ;next byte
loop theLoop ;loop for 16 times
output bracket1 ;print [
mov ecx, 16 ;mov 16 into ecx for looping
printer: output [ebx] ;print the character
add ebx, 16 ;next byte
loop printer ;loop until 16 characters are printed
output bracket2 ;output ]
popad ;pop registers
pop ebp ;retrive ebp
ret 4 ;return 4
lineBuffer endp
hexBPrint proc
push ebp ;saving ebp
mov ebp, esp ;copy stack pointer
pushad ;push registers
mov eax, [ebp+8] ;ascii character
lea ebx,dum+1 ; address for last character
mov ecx,2 ; number of characters
forCount: mov edx,eax ; copy pattern
and edx,0fh ; zero all but last hex digit
cmp edx,9 ; digit?
jnle elseLetter ; letter if not
or edx,30h ; convert to character
jmp endifDigit
elseLetter: add edx,'A'-10 ; convert to letter
endifDigit:
mov BYTE PTR [ebx],dl; copy character to memory
dec ebx ; point at next character
shr eax,4 ; shift one hex digit right
loop forCount ; repeat
output dum ;output byte in hex
popad ;pop registers
pop ebp ;retrive ebp
ret 4 ;return 4
hexBPrint endp
One address from MyList is pushed and then lineBuffer is called.