In: Computer Science
It is required that this program be written in ARM Assembly using raspberry pi. Submit an ARM assembly program that does the following:
1. Prompt for the user to enter a number (integer).
2. If the entered number is <100 print: "The input number is less than 100."
3. If the entered number is >=100 print: "The input number is greater than or equal to 100."
4. Prompt for the user to enter a single character.
5. If the entered character is lower case (a..z) print: "Lower case letter entered."
6. If the entered character is upper case (A..Z) print: "Upper case letter entered."
7. Otherwise print: "Special character entered." 8. Return control to the operating system.
I SEE THIS QUESTION HAS BEEN POSTED IN THE PAST AND NEVER RECEIVED A CORRECT ANSWER. THIS PROGRAM MUST BE WRITTEN IN ARM ASSEMBLY USING THE ARM PROCESSOR FOUND ON A RASPBERRY PI. IT CAN ALSO BE WRITTEN USING THE RASPBERRY PI EMULATOR THAT CAN BE FOUND ONLINE FOR FREE. PLEASE DO NOT POST THE ANSWER IN A DIFFERENT PROGRAMMING LANGUAGE. THANK YOU!
Code to take integer and validate the input:
@ Scanning an int and checking the value < 100
@ checkInteger.s
@ The C example for this code would be:
@
@ int num = 0;
@ printf( "> " );
@ scanf( "%d", &num );
@ if (num < 100) { printf("The input number is less than 100\n");
@ else { printf(" The input number is greater than or equal to 100.")}
@ print( "your input: %d\n", num ) ;
@
@ ---------------------------------------
@ Data Section
@ ---------------------------------------
.data
.balign 4
prompt: .asciz ">Enter a number"
format: .asciz "%d"
num: .int 0
output: .asciz "The input number %d is less than 100\n"
output2 : .asciz "The input number %d is greater than or equal to 100."
@ ---------------------------------------
@ Code Section
@ ---------------------------------------
.text
.global main
.extern printf
.extern scanf
main: push {ip, lr} @ push return address + dummy register
@ for alignment
ldr r0, =prompt @ print the prompt
bl printf
ldr r0, =format @ call scanf, and pass address of format
ldr r1, =num @ string and address of num in r0, and r1,
bl scanf @ respectively.
cmp ax, 100
jl Less
ldr r1, =num @ print num formatted by output string.
ldr r1, [r1]
ldr r0, =output2
bl printf
jmp Both
Less:
ldr r1, =num @ print num formatted by output string.
ldr r1, [r1]
ldr r0, =output
bl printf
Both:
pop {ip, pc} @ pop return address into pc
pi@raspberrypi ~/temp $ make as -o checkInteger.o checkInteger.s gcc -o checkInteger checkInteger.o pi@raspberrypi ~/temp $ ./checkInteger >Enter a number235 The input number 235 is greater than or equal to 100. pi@raspberrypi ~/temp $
Program for character handling:
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'Enter the character : $'
MSG_1 DB 'The input letter is : $'
MSG_2 DB ' Lower case letter entered.'
MSG_3 DB ' Upper case letter entered.'
MSG_4 DB ' Special character entered.'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, PROMPT ; load and print PROMPT
MOV AH, 9
INT 21H
MOV AH, 1 ; read a character
INT 21H
MOV BL, AL ; save the input character into BL
MOV AH, 2 ; carriage return
MOV DL, 0DH
INT 21H
MOV DL, 0AH ; line feed
INT 21H
CMP BL, "A" ; compare input character and "A"
JB @DISPLAY ; jump to label @DISPLAY if input<A
CMP BL, "Z" ; compare input character and "Z"
JA @DISPLAY ; jump to label @DISPLAY if input>Z
LEA DX,MSG_1 ; load and print MSG_1
MOV AH, 9
INT 21H
MOV AH, 2 ; print the character
MOV DL, BL
INT 21H
CMP BL, "a" ; compare input character and "a"
JB @DISPLAY ; jump to label @DISPLAY if input<a
CMP BL, "Z" ; compare input character and "z"
JA @DISPLAY2 ; jump to label @DISPLAY if input>z
LEA DX,MSG_1 ; load and print MSG_1
MOV AH, 9
INT 21H
MOV AH, 2 ; print the character
MOV DL, BL
INT 21H
JMP @EXIT ; jump to label @EXIT
@DISPLAY: ; jump label
LEA DX,MSG_2 ; load and print MSG_2
MOV AH, 9
INT 21H
@DISPLAY2: ;jump label
LEA DX,MSG_3 ;load and print MSG_2
MOV AH, 9
INT 21H
@EXIT: ; jump label
LEA DX,MSG_4 ; load and print MSG_2
MOV AH, 9
INT 21H
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN