how to convert decimal to binary using ArmV8 assembly language Example: input: 43 output: 101011
I mainly dont know how to do the conversion part from decimal to binary
or how to translate it from any programming language to ARMv8
this is what I have
ARMv8 assembly language code
.data
decimal: .asciz "%s"
binary: .asciz "%d"
newline: .asciz "\n"
string_input_buffer: .space 256
userPrompt: .asciz "Input an integer: \n"
.text
.global main
main:
# Load the input prompt and print it out
ldr x0, =userPrompt
bl printf
# Take in the input and save it in the buffer
ldr x0, =decimal
ldr x1, =string_input_buffer
bl scanf
bl decToBin
done:
mov x0, #0
mov x8,#93
svc #0
decToBin:
// Convert Decimal to Binary
this is the code that I have in java
while(decimal != 0)
{
a = decimal%2;
b += a* Math.pow(10, count);
count++;
decimal = decimal/2;
}
I cant seem to understand how to translate it to arm
Since you are writing Assembly I assume you already understand that the number is already stored in the memory and the registers in a binary format and each operation manipulating it, is a binary operation as well.
What the java code you have does, is creating an integer with the exact same digits of its unsigned binary representation, which of course has a different value and as a result a different binary representation itself. I find it very hard to imagine what you can do with this produced integer except for printing it, but in java there are already built-in functions for that: Print an integer in binary format in Java
In fact, the first step of such a function is converting each of the digit to its corresponding character in order to be printed as such. This is the same process which would be followed for your constructed integer as well in order to be printed. Thus, creating such an integer seems redundant to me. So the question is: "Is this what you really want to do?"