Sunteți pe pagina 1din 14

Department Of Computer Science

University of the Western Cape


CSC 212
Architecture
ARM Assembler Programming
Teaching Staff
 Lecturers
 Dr. Hope Mauwa (hmauwa@uwc.ac.za)
 A/Prof. Antoine Bagula (abagula@uwc.ac.za)
 Practical Assistants
 Mr. André Henney (ahenney@uwc.ac.za)
What is Arm?
 ARM is a central processing unit (CPU).
 ARM processors are known as Reduced Instraction Set
Computing (RISC).

 ARM processor can be seen as a very powerful


calculator.

 Mobile phones, tablets, wearables, routers and other


Internet of Things (IoT) devices e.g. Raspberry Pi.

 R0-R12, R13 (Stack Pointer), R14 (Link R egister)and


R15 (Program Counter).
What is Arm? Continued…
 Load/store architecture.
 load To load a value from memory, you copy the data
from memory into a register.
 store To store a value to memory, you copy the data
from a register to memory.
 Only load and store instructions can access memory
 Does not support memory to memory data processing
operations.
 Must move data values into registers before using
 them.
Load and Store…
 The basic load and store instructions are:
 LDR STR Word
 LDRB STRB Byte
 LDRH STRH Halfword
 LDRSB Signed byte load
 LDRSH Signed halfword load
 .data
string: .asciz "\nHello World!\n”
.extern printf
main:
push {ip, lr}
ldr r0, =string
bl printf
pop {ip, pc}
ARM Assembler
ARM Assembler…
Why Assembler?
 Why not assembly, maybe just because of curiousity!
 Better memory access and management.
 You will be as close to the hardware as possible.
 Hack maybe---Ethically!!!!
 To learn about Computer Architecture, Assembly
programming is better to use a tool to learn.
Tools
 Raspberry Pi Emulator
 Qemu Emulator - http://www.qemu.org/

 Download
 http://cs.uwc.ac.za/~ahenney/qemu.zip.

 https://sourceforge.net/projects/rpiqemuwindows/files/latest/d
ownload

 Follow the “Downloading the MatrixPi” section in the


practical sheet.
Practical 1
Default Structure

 myAssemblerfile.s
@myAssemblyfile.s
.global main
main:
mov r0, #2
bx lr
Instruction Syntax
 <operation>{cond}{flags} Rd,Rn,Operand2
 <operation> - A three-letter mnemonic, e.g. MOV or ADD.
 {cond} - An optional two-letter condition code, e.g. EQ or
CS.
 {flags} - An optional additional flags. e.g. S.
 Rd - The destination register.
 Rn - The first source register.
 Operand2 - A flexible second operand.
Compile, Link, Run and Display

 Compile
as -o myAssemblerfile.o myAssemblerfile.s

 Link
gcc –o myAssemblerprogram myAssemblerfile.o

 Run
./myAssemblerprogram

 Display
./myAssemblerprogram ; echo $?
Practical Hints

 Question 1 a
mov r2, #4
add r0, r1, r2

 Question 1b
gcd:
cmp r0, r1 @ compare r0 and r1
subgt r0, r0, r1@ if r0 > r1, r0 = r0 - r1
sublt r1, r1, r0 @ if r0 < r1, r1 = r1 - r0
bne gcd @ if r0 != r1, repeat
Practical Due Date

Friday, 17 thAugust 2018 @


5:00PM

S-ar putea să vă placă și