Question
.global _start _start: mov R0,#0b101101 @ An arbitrary sample binary value for testing bl v_bin @ call subroutine to view binary value of R0 in
.global _start _start: mov R0,#0b101101 @ An arbitrary sample binary value for testing bl v_bin @ call subroutine to view binary value of R0 in ASCII. mov R0,#0 @ Exit Status code set to 0 indicates "normasl completion" mov R7,#1 svc 0
v_bin: push (R0-R7) @ Save contents of registers R0 through R7. sub R6,R2,#1 @ Number of bits to displayt (-1) cmp R6,#31 @ Test error value entered (bit31 is lefmost bit). movhi R6,#0 @ If bad range, default to displaying only 1 bit. mov R3,R0 @ R3 will hold a copy of input word to be displayed. mov R4,#1 @ Used to mask off 1 bit at a time for display. ldr R5,=dig @ Pointer to the "01" string of ASCII characters. mov R0,#1 @ Code for stdout (standard output, i.e., monitor display) mov R7,#4 @ Linux service command code to write string.
@ Loop through single bits and output each to the standard output (stdouyt) display. nxtbit and R1,R4,R3,lsr R6 @ Select next 0 or 1 to be displayed. add R1,R5 @ Set R1 pointng to "0" or "1" in memory svc 0 @ Linux service command code to write string. subs R6,#1 @ Decrement number of bits remaining to display. bge nxtbit @ Go display next bit untill all 32 displayed pop {R0-R7} @ Restore saved register contents bx LR @ Return to the calling program
.data dig: .ascii "01" @ ASCII string of binary digits 0 and 1 .end
- modify v_bin subroutine to precede binary with "0b"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started