EEE415 Week04 Machine Language
EEE415 Week04 Machine Language
Week 4
ARM v8 (Aarch64)
• So,the instruction set and rules are not universal for all architectures
(even other ARM architectures are different)
Cmd Format
0xE2432EFF
Dr. Sajid Muhaimin Choudhury 24
EEE 415 - Department of EEE, BUET Digital Design and Computer Architecture: ARM® Edition © 2015
DP Instruction with Register Src2
• Src2 can be:
▪ Immediate
▪ Register
▪ Register-shifted register
0xE0865007
Dr. Sajid Muhaimin Choudhury 27
EEE 415 - Department of EEE, BUET Digital Design and Computer Architecture: ARM® Edition © 2015
DP Instruction with Register Src2
• Rm: the second source operand
Shift Type sh
• shamt5: the amount Rm is shifted LSL 002
• sh: the type of shift LSR 012
ASR 102
ROR 112
Now, consider shifted versions.
Shift Type sh
LSL 002
LSR 012
ASR 102
ROR 112
Week 4
Week 4
Week 4
0xBA000003
0xEBFFFFFA
Branch
Machine Code
31:28 27:26 25 24:21 20 19:16 15:12 11:7 6:5 4 3:0
Week 3
Stored Program
Address Instructions Program Counter
(PC): keeps track of
current instruction
0000000C E5 9 1 3 0 0 0
00000008 E2 8 1 3 0 0 2
00000004 E3 A 0 2 0 4 5
00000000 E3 A 0 1 0 6 4 PC
Main Memory
NOP
• NOP is a mnemonic for “no operation” and is pronounced “no op.” It is a
pseudoinstruction that does nothing. The assembler translates it to MOV R0, R0
(0xE1A00000). NOPs are useful to, among other things, achieve some delay
or align instructions.
Exceptions
Lecture 4.3
Week 4
Dr. Sajid Muhaimin Choudhury, Assistant Professor
Department of Electrical and Electronics Engineering
Bangladesh University of Engineering and Technology
9
2
Exceptions
• An exception is like an unscheduled function call that branches to a new
address.
Exception Handling
• Like any other function call, an exception must save the return address, jump to
some address, do its work, clean up after itself, and return to the program where
it left off. Exceptions use a vector table to determine where to jump to the
exception handler and use banked registers to maintain extra copies of key
registers so that they will not corrupt the registers in the active program.
Privilege levels are important so that buggy or malicious user code cannot corrupt other programs or crash or infect
the system.
Banked Registers
• Before an exception changes the PC, it must save the return address in the LR
so that the exception handler knows where to return. However, it must take care
not to disturb the value already in the LR, which the program will need later.
Therefore, the processor maintains a bank of registers to use as separate LR
during each of the execution modes.
• Bank of Link Registers
• Bank of Saved Program Status Registers
• Banked copy of Stack Pointer
• FIQ mode: R8-R12 are banked
Exception Handling
At the start of Exception Handling…
1. Stores the CPSR into the banked SPSR
2. Sets the execution mode and privilege level based on the type of exception
3. Sets interrupt mask bits in the CPSR so that the exception handler will not be
interrupted
4. Stores the return address into the banked LR
5. Branches to the exception vector table based on the type of exception
• The processor then executes the instruction in the exception vector table,
typically a branch to the exception handler.
• The handler usually pushes other registers onto its stack, takes care of the
exception, and pops the registers back off the stack.
• The exception handler returns using the MOVS PC, LR
Exception Handling
MOVS PC,LR does the following clean up:
1. Copies the banked SPSR to the CPSR to restore the status register
2. Copies the banked LR (possibly adjusted for certain exceptions) to the PC to
return to the program where the exception occurred
3. Restores the execution mode and privilege level
Microarchitecture