On donne un nombre et on boucle tant que i >= 0 et on revoint soit 0 si i est pair ou 1 si i est impaire.
let i = input;
while (i >= 0) do (
if (i mod 2 = 0)
then (output 0)
else (output 1);
let i = i - 1
).
DATA SEGMENT
i DD
DATA ENDS
CODE SEGMENT
in eax
mov i, eax
debut_while_0:
mov eax, i
push eax
mov eax, 0
pop ebx
sub ebx, eax
jge vrai_gte_1
push 0
jmp fin_gte_1
vrai_gte_1:
push 1
fin_gte_1:
jz fin_while_0
mov eax, i
push eax
mov eax, 2
pop ebx
mov ecx, eax
mov eax, ebx
div ebx, ecx
mul ebx, ecx
sub eax, ebx
push eax
mov eax, 0
pop ebx
mov ecx, eax
sub ecx, ebx
jg faux_eq_3
mov ecx, ebx
sub ecx, eax
jg faux_eq_3
push 1
jmp fin_eq_3
faux_eq_3:
push 0
fin_eq_3:
jz sinon_2
mov eax, 0
out eax
jmp fin_si_2
sinon_2:
mov eax, 1
out eax
fin_si_2:
mov eax, i
push eax
mov eax, 1
pop ebx
sub ebx, eax
mov eax, ebx
mov i, eax
jmp debut_while_0
fin_while_0:
CODE ENDS
let a = input;
let b = input;
output a + b.
DATA SEGMENT
a DD
b DD
DATA ENDS
CODE SEGMENT
in eax
mov a, eax
in eax
mov b, eax
mov eax, a
push eax
mov eax, b
pop ebx
add eax, ebx
out eax
CODE ENDS