Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Does the program in in Exercise 1 4 . 4 . 1 work correctly for both lowercase and uppercase alphabetic hex characters? Why or why
Does the program in in Exercise work correctly for both lowercase and uppercase alphabetic hex characters? Why or why not?
Exercise
Show that the main function in Listing works with the assembly language hexToInt function in Listing
@ hexToInts
@ Converts a hex text string to an int.
@ Calling sequence:
@ r address of string
@ bl hexToInt
@ returns equivalent int
@ : Bob Plantz
@ Define my Raspberry Pi
cpu cortexa
fpu neonfparmv
syntax unified @ modern syntax
@ Constant for assembler
equ gap, @ between alpha and numerical
equ NUL,
equ noascii,xf
@ The program
text
align
global hexToInt
type hexToInt, function
hexToInt:
sub sp sp @ space for saving regs
@ keeping byte sp align
str rsp @ save r
str rsp @ r
str rsp @ r
str fpsp @ fp
str lrsp @ lr
add fp sp @ set our frame pointer
mov r r @ string pointer
mov r @ accumulator ;
loop:
ldrb rr @ get char
cmp r NUL @ end of string?
beq allDone @ yes
lsl r r @ room for four bits
cmp r @ alpha char?
subhi r r gap @ yes, remove gap
and r r noascii @ strip off acsii
add r r r @ add in the four bits
add r r @ next char
b loop
allDone:
mov r r @ return accumulator;
ldr rsp @ restore r
ldr rsp @ r
ldr rsp @ r
ldr fpsp @ fp
ldr lrsp @ lr
add sp sp @ sp
bx lr @ return
Listing Function to convert a hexadecimal text string to an integer prog asm
incontext
hexConvertc
Prompts user for hex number and converts
it to an int.
: Bob Plantz
#include
#include "hexToInt.h
int writeStrchar ;
int readLnchar int;
int main
int theNumber;
char theString;
writeStrEnter up to bit hex number: ;
readLntheString;
theNumber hexToInttheString;
printfThe integer is: i
theNumber;
return ;
Listing Program to input a hexadecimal text string from the keyboard and convert it to the corresponding integer. Calls the hexToInt function in Listing C
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