Skity
Skity

Reputation: 131

New to assembly, trying to figure out a simple code

I'm trying to figure out this code's RAX's value at the end.

start:
mov $1024, %rax
mov $4096, %rbx
mov $2048, %rcx
xor %rdx, %rdx
sub %rcx, %rbx
cmp %rbx, %rax
jge loopa
jmp loopb
loopa:
cmp $4, %rdx
jg end
inc %rdx
loopb:
xchg %rax, %rbx
idiv %rbx
add %rdx, %rax
imul %rcx
jmp loopa
end:

what im doing is following the registers values, at the beginning RAX is defined as 1024, RBX as 4096, and RCX as 2048, but then the code uses XOR on RDX and later on compares it in loopa, but I don't seem to understand RDX initial value since it is not defined anywhere in the code, what am I missing?

Upvotes: 0

Views: 820

Answers (1)

Ben Steffan
Ben Steffan

Reputation: 1125

The initial value of rdx is not important here, because xor %rdx, %rdx sets all bits of rdx to zero. It is functionally equivalent to mov $0, %rdx.

Upvotes: 1

Related Questions