So I'm trying to separate an octet by parity and I don't quite understand how the conditional jumps work(I tried it separately and I don't understand how it works it)
Here is what I came up with:
bits 32
global start
extern exit,printf
import exit msvcrt.dll
import printf msvcrt.dll
segment data use32 class=data
s db '1', '2', '3', '4','5','7','8','9' ; declararea sirului initial s
l equ $-s ; stabilirea lungimea sirului initial l
d1 times l db 0
d2 times 1 db 0
format db "%s", 0
segment code use32 class=code
start:
mov ecx, l
mov esi, 0
jecxz Sfarsit
Repeta:
;loop so it gets all the elements from s
mov al, [s+esi]
mov bl,al
sub bl,'0'
cmp bl,2; if is even adds it to d1
JP et2
mov [d1+esi], al
inc esi
et2:
mov bl,al
sub bl,'0'
cmp bl,2; if is odd adds it to d2
JP et1
mov [d2+esi], al
inc esi
et1:
loop Repeta
Sfarsit: ;terminarea programului
;Daca dorim si afisarea sirului d, avem urmatoarele:
push dword d1 ; punem parametrii pe stiva de la dreapta la stanga
push dword format
call [printf] ;apelam functia printf
add esp, 4 * 2 ; eliberam parametrii de pe stiva
; exit(0)
push dword d2 ; punem parametrii pe stiva de la dreapta la stanga
push dword format
call [printf] ;apelam functia printf
add esp, 4 * 2 ; eliberam parametrii de pe stiva
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
I think the problem is the JP
but I'm not completely sure.