0
\$\begingroup\$

how can I know if a command is treating an immediate as a decimal or as a hexadecimal? For e.g div casts the values into decimal before it makes the arithmetic division:

.data
x: .quad 0x16
y: .quad 0x7
z: .space 8

.text
.global main
main:
    xor %rax, %rax
    xor %rbx, %rbx
    xor %rdx, %rdx
    movq x, %rax  
    movq y, %rbx
    div %rbx
    movq %rax, z
    ret

I'm getting those results:

enter image description here

and my guess is that div looks at the decimal value of the number inside a register (cast it from hex to dec) but is it always like that in all arithmetic commands? Are there commands from different type that also act like this? I've tried reading the manual, but it doesn't specified there, I found it out by accident when debugging in sasm.

Thank you very much for your time and attention.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ it appears that you are misunderstanding that there is no difference between decimal and hexadecimal when it relates to values in registers .... the two notations are for reading by a human ... it is same as "one", "un", "uno", "eins" ... they all refer to the same number \$\endgroup\$
    – jsotola
    Commented Nov 29, 2019 at 20:48
  • 1
    \$\begingroup\$ h'16 / h'07 = 3 -- and at your breakpoint, rax = 3. So, what's the issue? \$\endgroup\$
    – TimWescott
    Commented Nov 29, 2019 at 23:47

1 Answer 1

1
\$\begingroup\$

Registers hold numbers, so there is no conversion. It is up to you to think a number in hex or decimal.

\$\endgroup\$
1
  • \$\begingroup\$ ... or binary, or octal, or base 6, ... \$\endgroup\$
    – Transistor
    Commented Nov 29, 2019 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.