Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
