Introduction to C. Write a main() function that swaps the contents of two integer variables x and y.

Size: px
Start display at page:

Download "Introduction to C. Write a main() function that swaps the contents of two integer variables x and y."

Transcription

1 Introduction to C Write a main() function that swaps the contents of two integer variables x and y. void main(void){ int a = 10; int b = 20; a = b; b = a; } 1

2 Introduction to C Write a main() function that swaps the contents of two integer variables x and y. void main(void){ int a = 10; int b = 20; int temp; temp = a a = b; b = temp; } 2

3 Introduction to C Can it be done without a third variable? void main(void){ int a = 10; int b = 20; int temp; temp = a a = b; b = temp; } 3

4 Introduction to C Can it be done without a third variable? void main(void){ int a = 10; int b = 20; int temp; temp = a } a = b; b = temp; Arithmetic solution (+ -) Logical solution (xor) 4

5 Introduction to C Can we package the swapping code in a function? void main(void){ } int a = 10; int b = 20; int temp; temp = a a = b; b = temp; 5

6 Ch.3 The ARM Cortex-M MCU(s) 6

7 Text sections 3.1 ARM Cortex-M Architecture 7

8 What is ARM? The ARM architectures are reduced instruction set computer (RISC) instruction set architectures (ISA), developed by British company ARM Holdings, who have designed and licensed a family of computer processors that use these instruction set architectures; The 32-bit architecture was first developed in the 1980s by Acorn Computers Ltd to power their desktop machines and subsequently spun off as a separate company, now ARM Holdings. The name was originally an acronym for Acorn RISC Machine and subsequently, after the name Acorn was dropped, Advanced RISC Machine. Globally, as of 2013, it is the most widely used 32-bit ISA in terms of quantity produced. In 2010 alone, producers of chips based on ARM architectures reported shipments of 6.1 billion ARM-based processors, representing 95% of smartphones, 35% of digital televisions and set-top boxes and 10% of mobile computers. 8

9 CISC v. RISC Complex instruction set computers (CISC) Early computers offered CPUs that were much faster than available memories. Fetching instructions limited performance A single complex instruction could perform many operations Example: Find the zeros of a polynomial Complex instructions require many processor clock cycles to complete A program running on a CISC computer employed a relatively small number of complex instructions High code density 9

10 CISC v. RISC Reduced Instruction Set Computers (RISC) Memories match CPU speed No large penalty for instruction fetch Instructions simplified Load, store, operations only on data already in registers Single processor clock cycle per instruction A program running on a RISC computer employs a relatively larger number of simplified instructions Reduced code density 10

11 What is ARM? The ARM architecture is a Reduced Instruction Set Computer (RISC) architecture, as it incorporates these typical RISC features: A uniform register file load/store architecture, where data processing operates only on register contents, not directly on memory contents. Simple addressing modes, with all load/store addresses determined from register contents and instruction fields only. Pipelining effectively provides single cycle operation for many instructions. Overview of 11

12 M3 vs. M4 240 system interrupts with individual priorities (from only 32 in M0, M0+, M1), and one NMI M4F Overview of 12

13 M3/M4 NVIC = Nested Vectored Interrupt Previous ARM cores all used external interrupt controllers! Controller 13

14 Cortex-M3/M4 have a Harvard Microcontroller Architecture PPB Arm Cortex TM -M3 processor System bus Input ports Internal NVIC peripherals Output ports ICode bus Instructions Flash ROM DCode bus Data RAM Table source: 14

15 Cortex-M registers Either data or addresses General purpose registers Stack pointer Link register Program counter Register file R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (MSP) R14 (LR) R15 (PC) Special registers PSR PRIMASK FAULTMASK BASEPRI CONTROL R13 (PSP) Program status register Exception mask registers CONTROL register MSP MAIN STACK POINTER PSP PROCESS STACK POINTER 15

16 Program Status Registers: Application, Interrupt, Execution APSR IPSR EPSR N Z C V Q 31 0 Reserved Reserved ICI/IT T Reserved Reserved ICI/IT 8 ISR_NUMBER Reserved PSR N Z C V Q ICI/IT T Reserved ICI/IT ISR_NUMBER ICI = Interruptible-Continuable Instruction info. (Load/Store Multiple) IT = If-Then block info. Can be accessed either individually (xpsr), or collectively (PSR)

17 Condition Codes Bit Name Meaning (after +, -, *, / ) N negative result is negative Z zero result is zero V overflow signed overflow C carry unsigned overflow Q saturation saturation has occurred in one of the saturation instructions (e.g. SSAT, USAT see Sec.5 of the Cortex-M3/M4F Instruction Set) 17

18 QUIZ: How are the flags N, Z, C, V set after this addition?

19 QUIZ: How are the flags N, Z, C, V set after this addition?

20 MEMORY MAPS LM3S1968 LM4F k Flash ROM 64k RAM I/O ports Internal I/O PPB 0x x0003.FFFF 0x x2000.FFFF 0x x41FF.FFFF 0xE xE004.0FFF 20

21 Endianness Address 0x x The 16-bit number 1000 Data 0x03 0xE8 Big Endian Address 0x x Data 0xE8 0x03 Little Endian The 32-bit number 305,419,896 Address Data Address Data 0x x12 0x x78 0x x34 0x x56 0x x56 0x x34 0x x78 0x x12 Big Endian Little Endian ENDIANESS: BIG ENDIAN MSB STORED IN SMALLEST ADDRESS LITTLE ENDIAN LSB STORED IN SMALLEST ADDRESS CORTEX-M3/M4 USE LITTLE ENDIAN EOL1 21

22 QUIZ: C What is the rule for generating this sequence: ? Write a main() function that calculates the sum of the first twenty members of the sequence. 22

23 Doubly-tricky QUIZ We re visualizing the memory contents of a microcontroller. What number is stored in the 4-Byte word that starts at 0x0000D4? 23

24 QUIZ 1. How many registers are in the Cortex-M register file? 2. How may of those are general-purpose registers? 3. What is the meaning of general-purpose? 4. Explain the function of the LR and PC. 5. What is the function of the APSR? Explain briefly each of its 5 bits (flags). 6. The value stored in the 4 MSB of APSR is 0xD. Explain what this means. 24

25 Cortex-M registers Either data or addresses General purpose registers Stack pointer Link register Program counter Register file R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (MSP) R14 (LR) R15 (PC) Special registers PSR PRIMASK FAULTMASK BASEPRI CONTROL R13 (PSP) Program status register Exception mask registers CONTROL register 25

26 Not in text What is THUMB? APSR IPSR EPSR N Z C V Q 31 0 Reserved Reserved ICI/IT T Reserved Reserved ICI/IT 8 ISR_NUMBER Reserved PSR N Z C V Q ICI/IT T Reserved ICI/IT ISR_NUMBER Can be accessed either individually, or collectively under the name PSR 26

27 The Thumb-2 instruction set Variable-length instructions ARM instructions are a fixed length of 32 bits Thumb instructions are a fixed length of 16 bits Thumb-2 instructions can be either 16-bit or 32-bit Thumb-2 gives approximately 26% improvement in code density over ARM Thumb-2 gives approximately 25% improvement in performance over Thumb Cortex M3/M4 have only the Thumb-2 mode! (T bit in EPSR must always be 1) 27

28 ARM 32-BIT INSTRUCTION FORMAT 28

29 THUMB INSTRUCTION SET FORMAT 29

30 THUMB ARM TRANSLATION (performed in the hardware) 30

31 Thumb, Thumb-2, and Thumbnail The Cortex-M3/M4 use only the Thumb-2 instruction set (no 32-bit pure ARM) The Thumb-2 instruction set is a composite of both 32- bit ARM instructions and the restrictive 16-bit Thumb instructions Thumb-2 improves code density in comparison with the ARM instruction set, but it is virtually as fast as ARM In our class, we use only a subset of 30 Thumb-2 instructions, listed in Appendix 4. The author calls this subset Thumbnail. 31

32 Cortex-M3/M4 Operating Modes Thread mode is the foreground operating context This is the context in which the main program and associated subroutines operate ISR_NUMBER in IPSR is 0 Handler mode is the background operating context This is the context in which the ISRs operate Both operating modes employ the MSP EE 319K - Bard, Valvano, and Yerraballi 32

33 Typo in Sec Reset: Thread (a.k.a. foreground) mode is unprivileged! Source: ARM Cortex-M3 Introduction by ARM University Relations (linked on course webpage) 33

34 Text sections 3.2 Software Development 3.3 Cortex-M3/M4 Assembly Language 34

35 SW Development Environment Editor Keil TM uvision Source code Start ; direction register LDR R1,=GPIO_PORTD_DIR_R LDR R0,[R1] ORR R0,R0,#0x0F ; make PD3-0 output STR R0, [R1] Start Debug Session Simulated Microcontroller Processor Memory I/O Build Target (F7) Object code 0x x x F040000F 0x A 6008 Address Data Download Real Microcontroller Start Debug Session Processor Memory I/O 35

36 SW Development Environment Re-read Sections 2.3, 2.4,

37 Conventions used in representing Thumbnail instructions Ra Rd Rm Rn Rt represent 32-bit registers value any 32-bit value: signed, unsigned, or address {S} if present, instr. sets condition codes (NZCV) #im12 any value from 0 to 4095 #im16 any value from 0 to {Rd,} if present Rd is destination, otherwise Rn {cond} optional logical condition (see Table 3.2) label any address within the ROM op2 the value generated by <op2> {, shift} optional shift of a register {, off} optional offset applied to a register 37

38 Examples Is this imm12 or imm16? ADD R0, #42 ADD R0, R1, #42 ADD R2, R1, R12 ADDS R5, R5, #25 ADDEQ R10,R11,R12 ADC R5, R1, R3 ;add w/carry Can we apply both {S} and {cond} in the same instruction? No! 38

39 Multi-word addition ADDS R4, R0, R2 ;Add the least significant words. ADC R5, R1, R3 ;Add most significant words w/ carry. To be continued in the lab EOL2 39

40 Cortex-M3/M4 assembly language Label Opcode Operands Comment INIT MOV R0, #100 ;set table size Comments should explain why or how should not explain the opcode and its operands are a major component of self-documenting code 40

41 Conditional execution ADD R0, #42 ADD R0, R1, #42 ADD R2, R1, R12 ADDS R5, R5, #25 ADDEQ R10,R11,R12 ADC R5, R1, R3 ;add w/carry 41

42 Conditions for conditional execution Suffix Flags Meaning Condition Code Suffixes Unsigned 1) Put first value in register 2) CMPS second value 3) EQ NE HI HS LO BLS Signed 1) Put first value in register 2) CMPS second value 3) EQ NE GT GE LT LE Logical 1) Put first value in register 2) ANDS ORRS EORS, ORNS 3) EQ NE EQ Z = 1 Equal NE Z = 0 Not equal CS / HS C = 1 Higher or same, unsigned CC / LO C = 0 Lower, unsigned < MI N = 1 Negative PL N = 0 Positive or zero VS V = 1 Overflow VC V = 0 No overflow HI C = 1 and Z = 0 Higher, unsigned > LS C = 0 or Z = 1 Lower or same, unsigned GE N = V Greater than or equal, signed LT N V Less than, signed < GT Z= 0 and N = V Greater than, signed > LE Z=1 and N V Less than or equal, signed AL Can have any value Always. This is the default when no suffix is specified. OR NOT second operand is inverted 42

43 Understanding the conditions Consider the signed (i.e. two s complement) numbers X and Y 1) Put first value in a register, say R1: MOV R1, #X 2) CMPS (compare and set) with the second value: CMPS R1, #Y 3) Apply any instruction with the suffix EQ NE GT GE LT LE: ADDLE R3, R4, R5 Is X less than Y equivalent to N V? 43

44 Addressing modes Immediate Indexed PC-relative 44

45 Addressing Modes Immediate addressing the data is contained in the instruction MOV R0,# k Flash ROM 32k 64k RAM I/O ports 0x x0003.FFFF 0x x2000.FFFF 7FFF 0x x41FF.FFFF R0 PC 0x EEPROM Internal I/O PPB 0x x F04F 0064 MOV R0,#100 0x x C 0xE xE004.0FFF 45

46 Addressing Modes Indexed addressing the address of the data in memory is in a register LDR R0,[R1] ; R0= value pointed to by R1 PC R0 R1 0x x EEPROM 0x x LDR R0,[R1] 0x x x RAM 0x x x x C 46

47 Addressing Modes Indexed addressing with offset LDR R0,[R1,#4] 47

48 Addressing Modes PC Relative Addressing the address of data in EEPROM is indexed based upon the PC B location BL subroutine ;branch ;branch and link 48

49 What does this code do? PC-relative LDR R1, =Count ;Count stores 0x LDR R0, [R1] First, LDR R1,=Count 0x ROM space R1 0x Count Second, LDR R0,[R1] RAM space R0 Why can t we just store 0x in the LDR instruction itself? 49

50 Addressing philosophy Cortex-M3/M4 has a 32-bit address space Instructions are at most 32 bits long => not enough space in an instruction for an address EEPROM accesses can be indexed using the program counter The PC always points to EEPROM and it can be used to calculate an address relative to the value in the PC RAM accesses involve storing the address in EEPROM and then accessing it using indexed addressing relative to the PC Two instructions will typically be required to access RAM or I/O 50

51 Flexible second operand <op2> Constant ADD Rd, Rn, #const ;Rd=Rn+const ADD Rd, Rn, Rm Register w/optional shift ADD R0, R1, LSL #4 ;R0=R0+(R1*16) ADD R0, R1, R2, LSL #4 51

52 Data storage philosophy Memory object Register Example operand type Constants in ROM PC =Constant [PC,#28] Local variables SP [SP,#0x04] on the stack Global variables R0 R12 [R0] in RAM I/O ports R0 R12 [R0] 52

53 53

54 Thumbnail Instructions Memory Access Instructions LDR Rd, [Rn] ;load 32-bit number at [Rn] to Rd LDR Rd, [Rn,#off] ;load 32-bit number at [Rn+off] to Rd LDR Rd, =value ;set Rd equal to 32-bit value (PC rel) LDRH Rd, [Rn] ;load unsigned 16-bit at [Rn] to Rd LDRH Rd, [Rn,#off] ;load unsign. 16-bit at [Rn+off] to Rd LDRSH Rd, [Rn] ;load signed 16-bit at [Rn] to Rd LDRSH Rd, [Rn,#off] ;load signed 16-bit at [Rn+off] to Rd LDRB Rd, [Rn] ;load unsigned 8-bit at [Rn] to Rd LDRB Rd, [Rn,#off] ;load unsigned 8-bit at [Rn+off] to Rd LDRSB Rd, [Rn] ;load signed 8-bit at [Rn] to Rd LDRSB Rd, [Rn,#off] ;load signed 8-bit at [Rn+off] to Rd Why do we need separate instructions for signed and unsigned for 8 and 16 bits? (Why not for 32 bits?) 54

55 Why do we need separate instructions for signed and unsigned 8 and 16 bits? (Why not for 32 bits?) Find the representations of -21 on: 8 bits: 16 bits: 32 bits: EOL3 55

56 QUIZ: Conditionals What number is in R1 after this code has executed? MOV R1, #10 MOV R2, #20 MOV R6, #42 MOV R7, #41 CMPS R6, R7 ADDGT R1, R2 ADD R1, R2 56

57 QUIZ: Conditionals Would the result be different if the unsigned comparison were used instead? MOV R1, #10 MOV R2, #20 MOV R6, #42 MOV R7, #43 CMPS R6, R7 ADDHI R1, R2 ADD R1, R2 57

58 QUIZ: Conditionals 58

59 QUIZ: Addressing 59

60 QUIZ: Addressing 60

61 QUIZ: Addressing ADDS R12, R11, R10 ;! 61

62 QUIZ: Addressing Why are memory accesses done in two instructions, rather than just one? Give an example, assuming that variable num1 is located in the RAM at address 0x FC (!) 62

63 X-tra credit QUIZ: Addressing In the text explanation of PC-relative addressing (p.92), the number 28 appears. What does it mean? 63

64 Thumbnail Instructions Memory Access Instructions STR Rt, [Rn] ;store 32-bit Rt to [Rn] STR Rt, [Rn,#off] ;store 32-bit Rt to [Rn+off] STRH Rt, [Rn] ;store least sig. 16-bit Rt to [Rn] STRH Rt, [Rn,#off] ;store least sig. 16-bit Rt to [Rn+off] STRB Rt, [Rn] ;store least sig. 8-bit Rt to [Rn] STRB Rt, [Rn,#off] ;store least sig. 8-bit Rt to [Rn+off] PUSH {Rt} ;push 32-bit Rt onto stack POP {Rd} ;pop 32-bit number from stack into Rd ADR Rd, label ;set Rd equal to the address at label MOV{S} Rd, <op2> ;set Rd equal to op2 MOV Rd, #im16 ;set Rd equal to im16 (0 to 65535) MVN{S} Rd, <op2> ;set Rd equal to -op2 How come there are no signed/unsigned stores (by similarity with the loads)? 64

65 Thumbnail Instructions Memory Access Instructions STR Rt, [Rn] ;store 32-bit Rt to [Rn] STR Rt, [Rn,#off] ;store 32-bit Rt to [Rn+off] STRH Rt, [Rn] ;store least sig. 16-bit Rt to [Rn] STRH Rt, [Rn,#off] ;store least sig. 16-bit Rt to [Rn+off] STRB Rt, [Rn] ;store least sig. 8-bit Rt to [Rn] STRB Rt, [Rn,#off] ;store least sig. 8-bit Rt to [Rn+off] PUSH {Rt} ;push 32-bit Rt onto stack POP {Rd} ;pop 32-bit number from stack into Rd ADR Rd, label ;set Rd equal to the address at label MOV{S} Rd, <op2> ;set Rd equal to op2 MOV Rd, #im16 ;set Rd equal to im16 (0 to 65535) MVN{S} Rd, <op2> ;set Rd equal to -op2 65

66 Wasn t there an LDR that did the same thing? 66

67 PC-relative LDR vs. ADR ADR has only PC-relative addressing mode! DCD = Define Constant Data = assembler directive Count is an address in data memory (RAM) Pi is an address in code memory (FlashROM) 67

68 PC-relative LDR vs. ADR Is it possible to translate any PC-relative LDR into an ADR? 68

69 Can you figure out how many bits are used in the ADR instruction for the offset? 69

70 Are 13 bits sufficient to represent a jump from Flash ROM to RAM? 70

71 ADR vs. LDR/STR Loading a register with a pointer to an address in FlashROM ADR Rd, label Loading a register with a constant, address, or data LDR RD, =number LDR RD, =label LDR and STR are used to load/store RAM data or constants 71

72 Thumbnail Instructions Memory Access Instructions STR Rt, [Rn] ;store 32-bit Rt to [Rn] STR Rt, [Rn,#off] ;store 32-bit Rt to [Rn+off] STRH Rt, [Rn] ;store least sig. 16-bit Rt to [Rn] STRH Rt, [Rn,#off] ;store least sig. 16-bit Rt to [Rn+off] STRB Rt, [Rn] ;store least sig. 8-bit Rt to [Rn] STRB Rt, [Rn,#off] ;store least sig. 8-bit Rt to [Rn+off] PUSH {Rt} ;push 32-bit Rt onto stack POP {Rd} ;pop 32-bit number from stack into Rd ADR Rd, label ;set Rd equal to the address at label MOV{S} Rd, <op2> ;set Rd equal to op2 MOV Rd, #im16 ;set Rd equal to im16 (0 to 65535) MVN{S} Rd, <op2> ;set Rd equal to -op2 72

73 3.3.7 The Stack Last-in-first-out (LIFO) storage In Cortex M3/M4, it works only with 32-bit data! Stack pointer (SP = R13) points to the top element already on the stack SP is decremented before more data is placed on stack Incremented after data is removed PUSH and POP instructions used to load and retrieve data 73

74 Instruction sequence PUSH {R0} PUSH {R1} PUSH {R2} POP {R3} POP {R4} POP {R5} Operation SP PUSH {R0} PUSH {R1} PUSH {R2} SP SP 2 SP 1 1 POP {R5} POP {R4} POP {R3} 0x x2000.FFFC 74

75 Instruction sequence PUSH {R0} PUSH {R1} PUSH {R2} POP {R3} POP {R4} POP {R5} If R0 R5 initially contain the numbers 0 5 (respectively), what are the contents of R0 R5 after this sequence of instructions? Operation SP PUSH {R0} PUSH {R1} PUSH {R2} SP SP 2 SP 1 1 POP {R5} POP {R4} POP {R3} 0x x2000.FFFC 75

76 Use the stack to swap the contents of two registers e.g. R11 and R12 Operation SP PUSH {R0} PUSH {R1} PUSH {R2} SP SP 2 SP 1 1 POP {R5} POP {R4} POP {R3} 0x x2000.FFFC EOL4 76

77 Use the stack to swap the contents of two registers e.g. R11 and R12 Operation SP PUSH {R0} PUSH {R1} PUSH {R2} SP SP 2 SP 1 1 POP {R5} POP {R4} POP {R3} 0x x2000.FFFC 77

78 Use the stack to reverse the contents of four registers: R9 R10 R11 R12. Draw stack after each operation. 78

79 Instruction sequence PUSH {R0} PUSH {R1} PUSH {R2} POP {R3} POP {R4} POP {R5} Operation What is the addressing mode of PUSH and POP? SP PUSH {R0} PUSH {R1} PUSH {R2} SP SP 2 SP 1 1 POP {R5} POP {R4} POP {R3} 0x x2000.FFFC 79

80 3.3.8 Branch Instructions B label ;branch to label Always BEQ label ;branch if Z == 1 Equal BNE label ;branch if Z == 0 Not equal BCS label ;branch if C == 1 Higher or same, unsign. BHS label ;branch if C == 1 Higher or same, unsign. BCC label ;branch if C == 0 Lower, unsign. < BLO label ;branch if C == 0 Lower, unsign. < BMI label ;branch if N == 1 Negative BPL label ;branch if N == 0 Positive or zero BVS label ;branch if V == 1 Overflow 80

81 Branch Instructions BVC label ;branch if V == 0 No overflow BHI label ;branch if C==1 and Z==0 unsigned > BLS label ;branch if C==0 or Z==1 unsigned BGE label ;branch if N == V signed BLT label ;branch if N!= V signed < BGT label ;branch if Z==0 and N==V signed > BLE label ;branch if Z==1 and N!=V signed BX Rm ;branch indirect to location specified by Rm BL label ;branch to subroutine at label BLX Rm ;branch to subroutine indexed by Rm 81

82 Branch instr. in a nutshell BVC label ;branch to label BX Rm ;branch indirect to location specified by Rm BL label ;branch to subroutine at label BLX Rm ;branch to subroutine indexed by Rm They can all accept conditional suffixes 82

83 What does this program do? 83

84 What does this program do? Sequence Conditional While-loop Block 1 Block 2 Block 1 Block 2 Block 84

85 What does this program do? 85

86 What does this program do? 86

87 Functions a.k.a. subroutines Do you recognize this sequence? main Num = 0 Change() Change Num = Num+25 Return Last instruction in a function is always this 87

88 One convention used in ARM-Cortex programming is that function parameters are passed in the registers R0-R3. Re-write the code below with the value of Num passed in R3. 88

89 Another convention used in ARM-Cortex programming is that the function return value is passed in R0. Re-write the code below with the value of Num passed back to the main program in R0. 89

90 Extra-credit: What is the problem with the C code? 90

91 Function management Problem: What if a function makes use of some of the registers used by the main program? Upon return, the main program should be able to continue its operation uninterrupted! Solution: Function pushes on the stack the registers it s going to use Before returning, it pops the same registers (in reverse order!) 91

92 Function management Rules for stack use Functions should have an equal number of pushes and pops Stack accesses (push or pop) should not be performed outside the allocated area Stack reads and writes should not be performed within the free area Stack push should first decrement SP, then store the data Stack pop should first read the data, and then increment SP 92

93 QUIZ: Subroutines 93

94 3.3.5 Logical Instructions AND{S} {Rd,} Rn, <op2> ; Rd=Rn&op2 (op2 is 32 bits) ORR{S} {Rd,} Rn, <op2> ; Rd=Rn op2 (op2 is 32 bits) EOR{S} {Rd,} Rn, <op2> ; Rd=Rn^op2 (op2 is 32 bits) BIC{S} {Rd,} Rn, <op2> ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S} {Rd,} Rn, <op2> ; Rd=Rn (~op2) (op2 is 32 bits) LSR{S} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S} Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL{S} Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned) 94

95 QUIZ: Logical Instructions AND{S} {Rd,} Rn, <op2> ; Rd=Rn&op2 (op2 is 32 bits) ORR{S} {Rd,} Rn, <op2> ; Rd=Rn op2 (op2 is 32 bits) EOR{S} {Rd,} Rn, <op2> ; Rd=Rn^op2 (op2 is 32 bits) BIC{S} {Rd,} Rn, <op2> ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S} {Rd,} Rn, <op2> ; Rd=Rn (~op2) (op2 is 32 bits) LSR{S} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S} Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL{S} Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned) Write a program to flip all bits in R0 95

96 QUIZ: Logical Instructions AND{S} {Rd,} Rn, <op2> ; Rd=Rn&op2 (op2 is 32 bits) ORR{S} {Rd,} Rn, <op2> ; Rd=Rn op2 (op2 is 32 bits) EOR{S} {Rd,} Rn, <op2> ; Rd=Rn^op2 (op2 is 32 bits) BIC{S} {Rd,} Rn, <op2> ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S} {Rd,} Rn, <op2> ; Rd=Rn (~op2) (op2 is 32 bits) LSR{S} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S} Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL{S} Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned) Write a program to flip all odd bits in R0 96

97 QUIZ: Logical Instructions AND{S} {Rd,} Rn, <op2> ; Rd=Rn&op2 (op2 is 32 bits) ORR{S} {Rd,} Rn, <op2> ; Rd=Rn op2 (op2 is 32 bits) EOR{S} {Rd,} Rn, <op2> ; Rd=Rn^op2 (op2 is 32 bits) BIC{S} {Rd,} Rn, <op2> ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S} {Rd,} Rn, <op2> ; Rd=Rn (~op2) (op2 is 32 bits) LSR{S} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S} Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL{S} Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned) Write a program to set (=1) the 8 upper bits in R0, and leave all the rest unchanged. 97

98 Homework for Ch.3 End of chapter: 6, 9, 10, 22, 23, 25 Not from text: Write a function in assembly Main program passes values of two integers in R1 and R2 Function returns their sum in R0 98

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name: EE319K Fall 2012 Exam 1A Modified Page 1 Exam 1 Fun Times Date: October 5, 2012 Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will

More information

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map (14) Question 1. For each of the following components, decide where to place it within the memory map of the microcontroller. Multiple choice select: RAM, ROM, or other. Select other if the component is

More information

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name: EE319K Exam 1 Summer 2014 Page 1 Exam 1 Date: July 9, 2014 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help

More information

Exam 1. Date: Oct 4, 2018

Exam 1. Date: Oct 4, 2018 Exam 1 Date: Oct 4, 2018 UT EID: Professor: Valvano Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat

More information

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015 EE319K Spring 2015 Exam 1 Page 1 Exam 1 Date: Feb 26, 2015 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help

More information

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013 EE319K Fall 2013 Exam 1B Modified Page 1 Exam 1 Date: October 3, 2013 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will

More information

Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013

Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013 The University of Texas at Austin Department of Electrical and Computer Engineering Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013 Midterm 1 Solutions Date: February 21, 2013 UT EID:

More information

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi EE319K Spring 2016 Exam 1 Solution Page 1 Exam 1 Date: Feb 25, 2016 UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi Printed Name: Last, First Your signature is your promise

More information

Cortex M3 Programming

Cortex M3 Programming Cortex M3 Programming EE8205: Embedded Computer Systems http://www.ee.ryerson.ca/~courses/ee8205/ Dr. Gul N. Khan http://www.ee.ryerson.ca/~gnkhan Electrical and Computer Engineering Ryerson University

More information

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones CprE 288 Introduction to Embedded Systems Course Review for Exam 3 Instructors: Dr. Phillip Jones 1 Announcements Exam 3: See course website for day/time. Exam 3 location: Our regular classroom Allowed

More information

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ARM Instruction Set Architecture Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Condition Field (1) Most ARM instructions can be conditionally

More information

The ARM Cortex-M0 Processor Architecture Part-2

The ARM Cortex-M0 Processor Architecture Part-2 The ARM Cortex-M0 Processor Architecture Part-2 1 Module Syllabus ARM Cortex-M0 Processor Instruction Set ARM and Thumb Instruction Set Cortex-M0 Instruction Set Data Accessing Instructions Arithmetic

More information

A block of memory (FlashROM) starts at address 0x and it is 256 KB long. What is the last address in the block?

A block of memory (FlashROM) starts at address 0x and it is 256 KB long. What is the last address in the block? A block of memory (FlashROM) starts at address 0x00000000 and it is 256 KB long. What is the last address in the block? 1 A block of memory (FlashROM) starts at address 0x00000000 and it is 256 KB long.

More information

Chapter 2 Instructions Sets. Hsung-Pin Chang Department of Computer Science National ChungHsing University

Chapter 2 Instructions Sets. Hsung-Pin Chang Department of Computer Science National ChungHsing University Chapter 2 Instructions Sets Hsung-Pin Chang Department of Computer Science National ChungHsing University Outline Instruction Preliminaries ARM Processor SHARC Processor 2.1 Instructions Instructions sets

More information

Comparison InstruCtions

Comparison InstruCtions Status Flags Now it is time to discuss what status flags are available. These five status flags are kept in a special register called the Program Status Register (PSR). The PSR also contains other important

More information

ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions

ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions M J Brockway February 17, 2016 Branching To do anything other than run a fixed sequence of instructions,

More information

ARM Cortex-M4 Architecture and Instruction Set 2: General Data Processing Instructions

ARM Cortex-M4 Architecture and Instruction Set 2: General Data Processing Instructions ARM Cortex-M4 Architecture and Instruction Set 2: General Data Processing Instructions M J Brockway January 31, 2016 Cortex-M4 Machine Instructions - simple example... main FUNCTION ; initialize registers

More information

ECE 571 Advanced Microprocessor-Based Design Lecture 3

ECE 571 Advanced Microprocessor-Based Design Lecture 3 ECE 571 Advanced Microprocessor-Based Design Lecture 3 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 22 January 2013 The ARM Architecture 1 Brief ARM History ACORN Wanted a chip

More information

ARM Assembly Language. Programming

ARM Assembly Language. Programming Outline: ARM Assembly Language the ARM instruction set writing simple programs examples Programming hands-on: writing simple ARM assembly programs 2005 PEVE IT Unit ARM System Design ARM assembly language

More information

The PAW Architecture Reference Manual

The PAW Architecture Reference Manual The PAW Architecture Reference Manual by Hansen Zhang For COS375/ELE375 Princeton University Last Update: 20 September 2015! 1. Introduction The PAW architecture is a simple architecture designed to be

More information

ARM Cortex-M4 Programming Model Flow Control Instructions

ARM Cortex-M4 Programming Model Flow Control Instructions ARM Cortex-M4 Programming Model Flow Control Instructions Textbook: Chapter 4, Section 4.9 (CMP, TEQ,TST) Chapter 6 ARM Cortex-M Users Manual, Chapter 3 1 CPU instruction types Data movement operations

More information

AND SOLUTION FIRST INTERNAL TEST

AND SOLUTION FIRST INTERNAL TEST Faculty: Dr. Bajarangbali P.E.S. Institute of Technology( Bangalore South Campus) Hosur Road, ( 1Km Before Electronic City), Bangalore 560100. Department of Electronics and Communication SCHEME AND SOLUTION

More information

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2016 1 ISA is the HW/SW

More information

STEVEN R. BAGLEY ARM: PROCESSING DATA

STEVEN R. BAGLEY ARM: PROCESSING DATA STEVEN R. BAGLEY ARM: PROCESSING DATA INTRODUCTION CPU gets instructions from the computer s memory Each instruction is encoded as a binary pattern (an opcode) Assembly language developed as a human readable

More information

ARM Shift Operations. Shift Type 00 - logical left 01 - logical right 10 - arithmetic right 11 - rotate right. Shift Amount 0-31 bits

ARM Shift Operations. Shift Type 00 - logical left 01 - logical right 10 - arithmetic right 11 - rotate right. Shift Amount 0-31 bits ARM Shift Operations A novel feature of ARM is that all data-processing instructions can include an optional shift, whereas most other architectures have separate shift instructions. This is actually very

More information

Chapter 15. ARM Architecture, Programming and Development Tools

Chapter 15. ARM Architecture, Programming and Development Tools Chapter 15 ARM Architecture, Programming and Development Tools Lesson 5 ARM 16-bit Thumb Instruction Set 2 - Thumb 16 bit subset Better code density than 32-bit architecture instruction set 3 Basic Programming

More information

ARM Cortex M3 Instruction Set Architecture. Gary J. Minden March 29, 2016

ARM Cortex M3 Instruction Set Architecture. Gary J. Minden March 29, 2016 ARM Cortex M3 Instruction Set Architecture Gary J. Minden March 29, 2016 1 Calculator Exercise Calculate: X = (45 * 32 + 7) / (65 2 * 18) G. J. Minden 2014 2 Instruction Set Architecture (ISA) ISAs define

More information

Flow Control In Assembly

Flow Control In Assembly Chapters 6 Flow Control In Assembly Embedded Systems with ARM Cortext-M Updated: Monday, February 19, 2018 Overview: Flow Control Basics of Flowcharting If-then-else While loop For loop 2 Flowcharting

More information

ECE 471 Embedded Systems Lecture 5

ECE 471 Embedded Systems Lecture 5 ECE 471 Embedded Systems Lecture 5 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 17 September 2013 HW#1 is due Thursday Announcements For next class, at least skim book Chapter

More information

Writing ARM Assembly. Steven R. Bagley

Writing ARM Assembly. Steven R. Bagley Writing ARM Assembly Steven R. Bagley Hello World B main hello DEFB Hello World\n\0 goodbye DEFB Goodbye Universe\n\0 ALIGN main ADR R0, hello ; put address of hello string in R0 SWI 3 ; print it out ADR

More information

ARM Cortex-M4 Programming Model Memory Addressing Instructions

ARM Cortex-M4 Programming Model Memory Addressing Instructions ARM Cortex-M4 Programming Model Memory Addressing Instructions References: Textbook Chapter 4, Sections 4.1-4.5 Chapter 5, Sections 5.1-5.4 ARM Cortex-M Users Manual, Chapter 3 2 CPU instruction types

More information

ARM Architecture and Assembly Programming Intro

ARM Architecture and Assembly Programming Intro ARM Architecture and Assembly Programming Intro Instructors: Dr. Phillip Jones http://class.ece.iastate.edu/cpre288 1 Announcements HW9: Due Sunday 11/5 (midnight) Lab 9: object detection lab Give TAs

More information

ARM Cortex-M4 Programming Model

ARM Cortex-M4 Programming Model ARM Cortex-M4 Programming Model ARM = Advanced RISC Machines, Ltd. ARM licenses IP to other companies (ARM does not fabricate chips) 2005: ARM had 75% of embedded RISC market, with 2.5 billion processors

More information

ARM Architecture and Instruction Set

ARM Architecture and Instruction Set AM Architecture and Instruction Set Ingo Sander ingo@imit.kth.se AM Microprocessor Core AM is a family of ISC architectures, which share the same design principles and a common instruction set AM does

More information

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC ECE425 MNEMONIC TABLE MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC Adds operands and Carry flag and places value in destination register ADD Adds operands and places value in

More information

Processor Status Register(PSR)

Processor Status Register(PSR) ARM Registers Register internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has 13 general-purpose registers R0-R12 1 Stack Pointer (SP) R13

More information

Unsigned and signed integer numbers

Unsigned and signed integer numbers Unsigned and signed integer numbers Binary Unsigned Signed 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 Subtraction sets C flag opposite of carry (ARM specialty)! - if (carry = 0) then C=1 - if (carry

More information

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS Introduction to 32 bit Processors, ARM Architecture, ARM cortex M3, 32 bit ARM Instruction set, Thumb Instruction set, Exception

More information

Chapters 5. Load & Store. Embedded Systems with ARM Cortex-M. Updated: Thursday, March 1, 2018

Chapters 5. Load & Store. Embedded Systems with ARM Cortex-M. Updated: Thursday, March 1, 2018 Chapters 5 Load & Store Embedded Systems with ARM Cortex-M Updated: Thursday, March 1, 2018 Overview: Part I Machine Codes Branches and Offsets Subroutine Time Delay 2 32-Bit ARM Vs. 16/32-Bit THUMB2 Assembly

More information

Raspberry Pi / ARM Assembly. OrgArch / Fall 2018

Raspberry Pi / ARM Assembly. OrgArch / Fall 2018 Raspberry Pi / ARM Assembly OrgArch / Fall 2018 The Raspberry Pi uses a Broadcom System on a Chip (SoC), which is based on an ARM CPU. https://en.wikipedia.org/wiki/arm_architecture The 64-bit ARM processor

More information

Topic 10: Instruction Representation

Topic 10: Instruction Representation Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Summer Session II Dr. Ali Irturk Dept. of Computer Science and Engineering University of California, San Diego

More information

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers Outline ARM Introduction & Instruction Set Architecture Aleksandar Milenkovic E-mail: Web: milenka@ece.uah.edu http://www.ece.uah.edu/~milenka ARM Architecture ARM Organization and Implementation ARM Instruction

More information

ARM Cortex-A9 ARM v7-a. A programmer s perspective Part 2

ARM Cortex-A9 ARM v7-a. A programmer s perspective Part 2 ARM Cortex-A9 ARM v7-a A programmer s perspective Part 2 ARM Instructions General Format Inst Rd, Rn, Rm, Rs Inst Rd, Rn, #0ximm 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7

More information

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls Instructors: Dr. Phillip Jones 1 Announcements Final Projects Projects: Mandatory

More information

3 Assembly Programming (Part 2) Date: 07/09/2016 Name: ID:

3 Assembly Programming (Part 2) Date: 07/09/2016 Name: ID: 3 Assembly Programming (Part 2) 43 Date: 07/09/2016 Name: ID: Name: ID: 3 Assembly Programming (Part 2) This laboratory session discusses about Secure Shell Setup and Assembly Programming. The students

More information

Lecture 15 ARM Processor A RISC Architecture

Lecture 15 ARM Processor A RISC Architecture CPE 390: Microprocessor Systems Fall 2017 Lecture 15 ARM Processor A RISC Architecture Bryan Ackland Department of Electrical and Computer Engineering Stevens Institute of Technology Hoboken, NJ 07030

More information

ARM Instruction Set 1

ARM Instruction Set 1 ARM Instruction Set 1 What is an embedded system? Components: Processor(s) Co-processors (graphics, security) Memory (disk drives, DRAM, SRAM, CD/DVD) input (mouse, keyboard, mic) output (display, printer)

More information

CS 310 Embedded Computer Systems CPUS. Seungryoul Maeng

CS 310 Embedded Computer Systems CPUS. Seungryoul Maeng 1 EMBEDDED SYSTEM HW CPUS Seungryoul Maeng 2 CPUs Types of Processors CPU Performance Instruction Sets Processors used in ES 3 Processors used in ES 4 Processors used in Embedded Systems RISC type ARM

More information

Chapter 15. ARM Architecture, Programming and Development Tools

Chapter 15. ARM Architecture, Programming and Development Tools Chapter 15 ARM Architecture, Programming and Development Tools Lesson 4 ARM CPU 32 bit ARM Instruction set 2 Basic Programming Features- ARM code size small than other RISCs 32-bit un-segmented memory

More information

ECE 498 Linux Assembly Language Lecture 5

ECE 498 Linux Assembly Language Lecture 5 ECE 498 Linux Assembly Language Lecture 5 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 29 November 2012 Clarifications from Lecture 4 What is the Q saturate status bit? Some

More information

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets EEM870 Embedded System and Experiment Lecture 4 ARM Instruction Sets Wen-Yen Lin, Ph.D. Department of Electrical Engineering Chang Gung University Email wylin@mail.cgu.edu.tw March 2014 Introduction Embedded

More information

OUTLINE. STM32F0 Architecture Overview STM32F0 Core Motivation for RISC and Pipelining Cortex-M0 Programming Model Toolchain and Project Structure

OUTLINE. STM32F0 Architecture Overview STM32F0 Core Motivation for RISC and Pipelining Cortex-M0 Programming Model Toolchain and Project Structure ARCHITECTURE AND PROGRAMMING George E Hadley, Timothy Rogers, and David G Meyer 2018, Images Property of their Respective Owners OUTLINE STM32F0 Architecture Overview STM32F0 Core Motivation for RISC and

More information

Interrupt-Driven Input/Output

Interrupt-Driven Input/Output Interrupt-Driven Input/Output Textbook: Chapter 11 (Interrupts) ARM Cortex-M4 User Guide (Interrupts, exceptions, NVIC) Sections 2.1.4, 2.3 Exceptions and interrupts Section 4.2 Nested Vectored Interrupt

More information

ARM Assembly Programming

ARM Assembly Programming Introduction ARM Assembly Programming The ARM processor is very easy to program at the assembly level. (It is a RISC) We will learn ARM assembly programming at the user level and run it on a GBA emulator.

More information

Control Flow. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 21

Control Flow. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 21 Control Flow Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 21 Outline Condition Codes C Relational Operations C Logical

More information

Architecture. Digital Computer Design

Architecture. Digital Computer Design Architecture Digital Computer Design Architecture The architecture is the programmer s view of a computer. It is defined by the instruction set (language) and operand locations (registers and memory).

More information

NET3001. Advanced Assembly

NET3001. Advanced Assembly NET3001 Advanced Assembly Arrays and Indexing supposed we have an array of 16 bytes at 0x0800.0100 write a program that determines if the array contains the byte '0x12' set r0=1 if the byte is found plan:

More information

ARM Ltd. ! Founded in November 1990! Spun out of Acorn Computers

ARM Ltd. ! Founded in November 1990! Spun out of Acorn Computers ARM Architecture ARM Ltd! Founded in November 1990! Spun out of Acorn Computers! Designs the ARM range of RISC processor cores! Licenses ARM core designs to semiconductor partners who fabricate and sell

More information

ECE251: Tuesday September 12

ECE251: Tuesday September 12 ECE251: Tuesday September 12 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen ARM Instruction Set Computer Organization and Assembly Languages g Yung-Yu Chuang with slides by Peng-Sheng Chen Introduction The ARM processor is easy to program at the assembly level. (It is a RISC)

More information

18-349: Introduction to Embedded Real- Time Systems Lecture 3: ARM ASM

18-349: Introduction to Embedded Real- Time Systems Lecture 3: ARM ASM 18-349: Introduction to Embedded Real- Time Systems Lecture 3: ARM ASM Anthony Rowe Electrical and Computer Engineering Carnegie Mellon University Lecture Overview Exceptions Overview (Review) Pipelining

More information

EE4144: ARM Cortex-M Processor

EE4144: ARM Cortex-M Processor EE4144: ARM Cortex-M Processor EE4144 Fall 2014 EE4144 EE4144: ARM Cortex-M Processor Fall 2014 1 / 10 ARM Cortex-M 32-bit RISC processor Cortex-M4F Cortex-M3 + DSP instructions + floating point unit (FPU)

More information

Overview COMP Microprocessors and Embedded Systems. Lectures 14: Making Decisions in C/Assembly Language II

Overview COMP Microprocessors and Embedded Systems. Lectures 14: Making Decisions in C/Assembly Language II OMP 3221 Microprocessors and Embedded Systems Lectures 14: Making Decisions in /Assembly Language II Overview ompare instruction mechanism Flag setting Instructions onditional Instructions onclusion http://www.cse.unsw.edu.au/~cs3221

More information

Control Flow Instructions

Control Flow Instructions Control Flow Instructions CSE 30: Computer Organization and Systems Programming Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1 So Far... v All instructions have

More information

Branch Instructions. R type: Cond

Branch Instructions. R type: Cond Branch Instructions Standard branch instructions, B and BL, change the PC based on the PCR. The next instruction s address is found by adding a 24-bit signed 2 s complement immediate value

More information

ARM Cortex-M4 Programming Model Logical and Shift Instructions

ARM Cortex-M4 Programming Model Logical and Shift Instructions ARM Cortex-M4 Programming Model Logical and Shift Instructions References: Textbook Chapter 4, Sections 4.1, 4.2, 4.3, 4.5, 4.6, 4.9 ARM Cortex-M Users Manual, Chapter 3 1 CPU instruction types Data movement

More information

The ARM Cortex-M0 Processor Architecture Part-1

The ARM Cortex-M0 Processor Architecture Part-1 The ARM Cortex-M0 Processor Architecture Part-1 1 Module Syllabus ARM Architectures and Processors What is ARM Architecture ARM Processors Families ARM Cortex-M Series Family Cortex-M0 Processor ARM Processor

More information

ECE 471 Embedded Systems Lecture 6

ECE 471 Embedded Systems Lecture 6 ECE 471 Embedded Systems Lecture 6 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 15 September 2016 Announcements HW#3 will be posted today 1 What the OS gives you at start Registers

More information

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the Introduction ARM Instruction Set The ARM processor is easy to program at the assembly level. (It is a RISC) We will learn ARM assembly programming at the user level l and run it on a GBA emulator. Computer

More information

Embedded System Design

Embedded System Design ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA ĐIỆN-ĐIỆN TỬ BỘ MÔN KỸ THUẬT ĐIỆN TỬ Embedded System Design Chapter 2: Microcontroller Series (Part 1) 1. Introduction to ARM processors 2.

More information

ARM Assembly Language

ARM Assembly Language ARM Assembly Language Introduction to ARM Basic Instruction Set Microprocessors and Microcontrollers Course Isfahan University of Technology, Dec. 2010 1 Main References The ARM Architecture Presentation

More information

ARM-7 ADDRESSING MODES INSTRUCTION SET

ARM-7 ADDRESSING MODES INSTRUCTION SET ARM-7 ADDRESSING MODES INSTRUCTION SET Dr. P. H. Zope 1 Assistant Professor SSBT s COET Bambhori Jalgaon North Maharashtra University Jalgaon India phzope@gmail.com 9860631040 Addressing modes When accessing

More information

Lecture 4 (part 2): Data Transfer Instructions

Lecture 4 (part 2): Data Transfer Instructions Lecture 4 (part 2): Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego Assembly Operands:

More information

6 THE ETRAX Introduction. Special registers. 6 The ETRAX 4

6 THE ETRAX Introduction. Special registers. 6 The ETRAX 4 6 THE ETRAX 4 6.1 Introduction The ETRAX 4 is the processor prior to the ETRAX 1 in the ETRAX family. The differences between the CRIS implementation in the ETRAX 1 and the ETRAX 4 are presented in this

More information

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan ARM Programmers Model Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan chanhl@maili.cgu.edu.twcgu Current program status register (CPSR) Prog Model 2 Data processing

More information

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) Instruction Set Architecture (ISA) Encoding of instructions raises some interesting choices Tradeoffs: performance, compactness, programmability Uniformity. Should different instructions Be the same size

More information

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza Name Student ID University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza Name of person to your left Name of person to your right Please

More information

Systems Architecture The ARM Processor

Systems Architecture The ARM Processor Systems Architecture The ARM Processor The ARM Processor p. 1/14 The ARM Processor ARM: Advanced RISC Machine First developed in 1983 by Acorn Computers ARM Ltd was formed in 1988 to continue development

More information

The ARM Instruction Set

The ARM Instruction Set The ARM Instruction Set Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr Topics Covered Data Processing Instructions Branch Instructions Load-Store Instructions

More information

The ARM processor. Morgan Kaufman ed Overheads for Computers as Components

The ARM processor. Morgan Kaufman ed Overheads for Computers as Components The ARM processor Born in Acorn on 1983, after the success achieved by the BBC Micro released on 1982. Acorn is a really smaller company than most of the USA competitors, therefore it initially develops

More information

Instructions: Language of the Computer

Instructions: Language of the Computer CS359: Computer Architecture Instructions: Language of the Computer Yanyan Shen Department of Computer Science and Engineering 1 The Language a Computer Understands Word a computer understands: instruction

More information

Introduction to the ARM Processor Using Intel FPGA Toolchain. 1 Introduction. For Quartus Prime 16.1

Introduction to the ARM Processor Using Intel FPGA Toolchain. 1 Introduction. For Quartus Prime 16.1 Introduction to the ARM Processor Using Intel FPGA Toolchain For Quartus Prime 16.1 1 Introduction This tutorial presents an introduction to the ARM Cortex-A9 processor, which is a processor implemented

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming ECE 362 https://engineering.purdue.edu/ee362/ Rick Reading and writing arrays Consider this C code again: int array1[100]; int array2[100]; for(n=0; n

More information

Introduction to the ARM Processor Using Altera Toolchain. 1 Introduction. For Quartus II 14.0

Introduction to the ARM Processor Using Altera Toolchain. 1 Introduction. For Quartus II 14.0 Introduction to the ARM Processor Using Altera Toolchain For Quartus II 14.0 1 Introduction This tutorial presents an introduction to the ARM Cortex-A9 processor, which is a processor implemented as a

More information

Exam 1. Date: February 23, 2018

Exam 1. Date: February 23, 2018 Exam 1 Date: February 23, 2018 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam:

More information

Assembler: Basics. Alberto Bosio October 20, Univeristé de Montpellier

Assembler: Basics. Alberto Bosio October 20, Univeristé de Montpellier Assembler: Basics Alberto Bosio bosio@lirmm.fr Univeristé de Montpellier October 20, 2017 Assembler Program Template. t e x t / S t a r t o f the program code s e c t i o n /.data / V a r i a b l e s /

More information

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language Assembly Language Readings: 2.1-2.7, 2.9-2.10, 2.14 Green reference card Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine

More information

Chapter 2. Instructions: Language of the Computer

Chapter 2. Instructions: Language of the Computer Chapter 2 Instructions: Language g of the Computer Stored Program Computers The BIG Picture Instructions represented in binary, just like data Instructions and data stored in memory Programs can operate

More information

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language Assembly Language Readings: 2.1-2.7, 2.9-2.10, 2.14 Green reference card Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine

More information

ECE251: Tuesday September 11

ECE251: Tuesday September 11 ECE251: Tuesday September 11 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

EE251: Tuesday September 5

EE251: Tuesday September 5 EE251: Tuesday September 5 Shift/Rotate Instructions Bitwise logic and Saturating Instructions A Few Math Programming Examples ARM Assembly Language and Assembler Assembly Process Assembly Structure Assembler

More information

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA CISC 662 Graduate Computer Architecture Lecture 4 - ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

F28HS2 Hardware-Software Interfaces. Lecture 6: ARM Assembly Language 1

F28HS2 Hardware-Software Interfaces. Lecture 6: ARM Assembly Language 1 F28HS2 Hardware-Software Interfaces Lecture 6: ARM Assembly Language 1 CISC & RISC CISC: complex instruction set computer original CPUs very simple poorly suited to evolving high level languages extended

More information

Embedded assembly is more useful. Embedded assembly places an assembly function inside a C program and can be used with the ARM Cortex M0 processor.

Embedded assembly is more useful. Embedded assembly places an assembly function inside a C program and can be used with the ARM Cortex M0 processor. EE 354 Fall 2015 ARM Lecture 4 Assembly Language, Floating Point, PWM The ARM Cortex M0 processor supports only the thumb2 assembly language instruction set. This instruction set consists of fifty 16-bit

More information

Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration)

Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration) CS1021 AFTER READING WEEK Mid-Semester Test NOW Thurs 8th Nov @ 9am in Goldsmith Hall (ALL students to attend at 9am) Final 2 Labs Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18

More information

ARM Processors ARM ISA. ARM 1 in 1985 By 2001, more than 1 billion ARM processors shipped Widely used in many successful 32-bit embedded systems

ARM Processors ARM ISA. ARM 1 in 1985 By 2001, more than 1 billion ARM processors shipped Widely used in many successful 32-bit embedded systems ARM Processors ARM Microprocessor 1 ARM 1 in 1985 By 2001, more than 1 billion ARM processors shipped Widely used in many successful 32-bit embedded systems stems 1 2 ARM Design Philosophy hl h Low power

More information

Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

More information

Computer Organization MIPS ISA

Computer Organization MIPS ISA CPE 335 Computer Organization MIPS ISA Dr. Iyad Jafar Adapted from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html CPE 232 MIPS ISA 1 (vonneumann) Processor Organization

More information

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization CISC 662 Graduate Computer Architecture Lecture 4 - ISA MIPS ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

Solution to the Problems and Questions

Solution to the Problems and Questions Solution to the Problems and Questions Chapter 1 Problems and Questions 1. Show an analog signal 2. Show a digital signal Springer International Publishing Switzerland 2015 A. Elahi, T. Arjeski, ARM Assembly

More information