Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

....Verizon 9:55 AM 99% In this assignment you will write code to convert a stri

ID: 3593481 • Letter: #

Question

....Verizon 9:55 AM 99% In this assignment you will write code to convert a string of 1's and 0's (a binary number represented as a string) and convert it to decimal. Your binary number (string) will always be exactly 8 digits long (a one byte binary number.) That is, the string will be 8 characters long (no trailing 0) Essentially you will write a loop that runs 8 times. Let currentpow be the current power of two you will add to your result. Initialize currentpow to 128. Each time through the loop you will look at one character in the string. If that character is a 0, you will do nothing. If that character is a 1, you must add currentpow to your result. At the end of your loop you should divide currentpow by 2 Some skeletal code is provided for you. You should initialize all of your values (loop counter, currentpow, result) between main and _loop. Between _loop and _print is your loop body where the work will be done When your loop is done the result value (that you want to print) must be in R4. Don't mess with parts of the code I give you, except to change the string stored in input to test different binary numbers in your program.

Explanation / Answer

.LC0:

.string "Enter a binary number(1s and 0s) "

.LC1:

.string "The Binary number is ="

.LC2:

.string "Its decimal equivalent is ="

main:

stp x29, x30, [sp, -48]!

add x29, sp, 0

str wzr, [x29, 44]

mov w0, 1

str w0, [x29, 40]

adrp x0, .LC0

add x1, x0, :lo12:.LC0

adrp x0, std::cout

add x0, x0, :lo12:std::cout

bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

add x1, x29, 28

adrp x0, std::cin

add x0, x0, :lo12:std::cin

bl std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

ldr w0, [x29, 28]

str w0, [x29, 36]

.L3:

ldr w0, [x29, 28]

cmp w0, wzr

ble .L2

ldr w1, [x29, 28]

mov w0, 26215

movk w0, 0x6666, lsl 16

smull x0, w1, w0

lsr x0, x0, 32

asr w2, w0, 2

asr w0, w1, 31

sub w0, w2, w0

lsl w0, w0, 1

lsl w2, w0, 2

add w0, w0, w2

sub w0, w1, w0

str w0, [x29, 32]

ldr w1, [x29, 32]

ldr w0, [x29, 40]

mul w0, w1, w0

ldr w1, [x29, 44]

add w0, w1, w0

str w0, [x29, 44]

ldr w0, [x29, 28]

mov w1, 26215

movk w1, 0x6666, lsl 16

smull x1, w0, w1

lsr x1, x1, 32

asr w1, w1, 2

asr w0, w0, 31

sub w0, w1, w0

str w0, [x29, 28]

ldr w0, [x29, 40]

lsl w0, w0, 1

str w0, [x29, 40]

b .L3

.L2:

adrp x0, .LC1

add x1, x0, :lo12:.LC1

adrp x0, std::cout

add x0, x0, :lo12:std::cout

bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

ldr w1, [x29, 36]

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov x2, x0

adrp x0, std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)

add x0, x0, :lo12:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)

mov x1, x0

mov x0, x2

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))

adrp x0, .LC2

add x1, x0, :lo12:.LC2

adrp x0, std::cout

add x0, x0, :lo12:std::cout

bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

ldr w1, [x29, 44]

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov x2, x0

adrp x0, std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)

add x0, x0, :lo12:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)

mov x1, x0

mov x0, x2

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))

mov w0, 0

ldp x29, x30, [sp], 48

ret

__static_initialization_and_destruction_0(int, int):

stp x29, x30, [sp, -32]!

add x29, sp, 0

str w0, [x29, 28]

str w1, [x29, 24]

ldr w0, [x29, 28]

cmp w0, 1

bne .L7

ldr w1, [x29, 24]

mov w0, 65535

cmp w1, w0

bne .L7

adrp x0, std::__ioinit

add x0, x0, :lo12:std::__ioinit

bl std::ios_base::Init::Init()

adrp x0, __dso_handle

add x2, x0, :lo12:__dso_handle

adrp x0, std::__ioinit

add x1, x0, :lo12:std::__ioinit

adrp x0, std::ios_base::Init::~Init()

add x0, x0, :lo12:std::ios_base::Init::~Init()

bl __cxa_atexit

.L7:

nop

ldp x29, x30, [sp], 32

ret

_GLOBAL__sub_I_main:

stp x29, x30, [sp, -16]!

add x29, sp, 0

mov w1, 65535

mov w0, 1

bl __static_initialization_and_destruction_0(int, int)

ldp x29, x30, [sp], 16

ret