I am using X86 Assembly and need to compare two buffers by character and reflect if they match or not in a third buffer
PsuedoCode:
Compare(ESI=msg_buffer_ptr, EDI=recover_buffer_ptr, EBX=err_buffer_ptr)
;Compare a character in ESI && EDI
;if ESI == 0 then we are at the end of the string and just return after adding add a 0 to EBX
;if they equal; " " -> EBX
;if it's a 0dh or 0ah, then transpose them into EBX
;else if they don't equal; "X" -> EBX
;Loop to next character
I'm having trouble figureing out how to access the by each character.
I believe that something like this should help you out. Keep in mind that this is NASM rather than MASM, but those two should be pretty much the same in terms of basic syntax. I don't know what you meant by "transpose", so I just copy the value from the original array to the "err" array.
Basically, looping by each character is done by having an index register (in this case, ecx) and accessing the array via byte instructions. In this case, the size of the instruction is given implicitly by the operands, for example mov al, [esi+ecx]
or cmp al, [edi+ecx]
- we just use a byte register.
Anyway, the code is written as a function. I assumed that no registers need to be saved by the callee.
compare:
xor ecx, ecx
.loop:
mov al, [esi+ecx]
test al, al
jz .end
cmp al, [edi+ecx]
je .equal
cmp al, 0xa
je .endloop
cmp al, 0xd
je .endloop
mov al, 'X'
jmp .endloop
.equal:
mov al, ' '
.endloop:
mov [ebx+ecx], al
add ecx, 1
jmp .loop
.end:
mov [ebx+ecx], byte 0
ret