| Hosted by CoCalc | Download
1
@ Define my Raspberry Pi -- modified for the Pi Zero
2
.cpu arm1176jzf-s
3
.fpu vfp
4
.syntax unified @ modern syntax
5
6
@ Useful source code constants
7
.equ STDIN, 0
8
.equ STDOUT, 1
9
.equ aLetter, -8 @ as discussed in class
10
.equ local, 8
11
12
@ Constant program data
13
.section .rodata
14
.align 2
15
promptMsg:
16
.asciz "Enter a character: "
17
.equ promptLngth,.-promptMsg
18
responseMsg:
19
.asciz "You entered: "
20
.equ responseLngth,.-responseMsg
21
22
@ Program code
23
.text
24
.align 2
25
.global main
26
.type main, %function
27
main:
28
sub sp, sp, 8 @ space for fp, lr
29
str fp, [sp, 0] @ save fp
30
str lr, [sp, 4] @ and lr
31
add fp, sp, 4 @ set our frame pointer
32
sub sp, sp, local @ allocate memory for local var
33
34
mov r0, STDOUT @ prompt user for input
35
ldr r1, promptMsgAddr
36
mov r2, promptLngth
37
bl write
38
39
mov r4, aLetter @ address to write to -- THIS IS A HINT
40
41
mov r0, STDIN @ from keyboard
42
add r1, fp, r4 @ address of aLetter[0] -- THIS IS ALSO A HINT
43
mov r2, 4 @ one char is changed to four chars
44
bl read
45
46
mov r0, STDOUT @ nice message for user
47
ldr r1, responseMsgAddr
48
mov r2, responseLngth
49
bl write
50
51
mov r0, STDOUT @ echo user's character
52
add r1, fp, aLetter @ address of aLetter
53
mov r2, 4 @ one char is changed to four chars
54
bl write
55
56
mov r0, 0 @ return 0;
57
add sp, sp, local @ deallocate local var
58
ldr fp, [sp, 0] @ restore caller fp
59
ldr lr, [sp, 4] @ lr
60
add sp, sp, 8 @ and sp
61
bx lr @ return
62
63
@ Addresses of messages
64
.align 2
65
promptMsgAddr:
66
.word promptMsg
67
responseMsgAddr:
68
.word responseMsg
69
70