NET3001. Assembly Language

Size: px
Start display at page:

Download "NET3001. Assembly Language"

Transcription

1 NET3001 Assembly Language

2 Sample Program task: given the number of students in class, and the number of students absent, add them to determine the total number of students plan number of students is stored in RAM at location 0x the number of students absent is stored in RAM, at location 0x load the contents of 0x into r4 load the contents of 0x into r5 add the contents r5 to the r4 store the result r4 into address 0x

3 Sample Program.text.global main main: // we are creating program // visible outside the obj file // a label to the symbol table mov r7, #0x // this is a number which // we will use as a base address ldr r4,[r7] ldr r5,[r7,#4] add r4, r4, r5 // read 0x into r4 // read 0x into r5 // add str r4,[r7,#0x10] //store it into 0x

4 Things to note wouldn't it be easier if we could use names instead of long numbers like 0x we'll get to that in a few slide further on you can't just reference a memory address you must load the memory address into a register and reference the address through that register the term base address means that you have a memory address, and you add/subtract small numbers from that this enables you to reference lots of memory that is clustered around the base address and it means that the cluster can be located anywhere in RAM

5 Assembly Directives cpu instructions create a flow of instructions at the current location pointer assembler directives do not create code, but direct the assembler to set a new location pointer create spaces in the flow set data strings into the flow add labels to the symbol table

6 Sample Program in Machine Code <main>: 0: e3a07202 mov r7, # ; 0x : e ldr r4, [r7] 8: e ldr r5, [r7, #4] c: e add r4, r4, r5 10: e str r4, [r7, #16]

7 2 step assembly the system we are using creates a program in two steps assembler translates assembly instructions into binary opcodes linker does not finalize where to store them leaves the result in an object file binds one or more object files and assigns the code to specific addresses creates an executable file (or loadable) the other steps are loading and debugging

8 Cross Assembler In this course, we are using a cross assembler we are using a Pentium/x86 processor to prepare the code that will run on a Cortex processor Similarly, later in the course, we will be using a cross compiler

9 Assembly Directives.text Short form for.section.text.data the linker will put this at 0x , after vectors Short form for.section.data the linker will put this at 0x section.bss.section.vectors the linker will put this at 0x // /*.. */ These all inform the assembler about where the subsequent code/data is to go

10 Assembler Directives.byte d.word d.ascii string.asciz string.string string create bytes in the data stream NOTE: just like in C/C++, a single quote 'a' is just a single character(char), but a double quote a is a string (char[])

11 Assembler Directives.fill n,s,f fills n times s bytes with f (s=1,2 or 4).space n,f.skip n,f fill n bytes with f.org n moves ahead by n bytes

12 Assembler Directives.equ.set. add entries to the symbol table if you use the symbol. it means the current location counter this may come in hand in obscure situations

13 Labels Any word beginning in the left hand column and ending with a colon is a label this causes an entry in the symbol table the value of this symbol is the value of the current location counter.text main: mov r1, #0x600 mov r4, #0 loop1: mov r12, #5 < set location = 0x0000 < create label main < create label loop1 add r4, r12, r4.data < set location = 0x byte 14 < location is now 0x

14 Assembly Instructions: Direction in the ARM and Cortex, all instructions operate from right to left, except STR in other CPU's, this may be different i386 is often right to left, but not always mov eax, #45 in MSP430, instructions operate from left to right mov #123, r12

15 Assembly Instructions: Vocabulary in the ARM/Cortex data movement within the ALU is move data movement to RAM/FLASH/IO is load or store mem-to-mem move is not possible in other CPU's this may be different registers memory i386: move is from reg/mem to reg/mem in is from i/o to reg out is from reg to i/o Motorola load is from mem/io to reg (same as ARM) store is from reg to mem/io (same as ARM) transfer is from reg to reg move is from mem/io to mem/io in MSP430, all data movement is move mov store load!! no mem-to-mem move

16 Data Movement CPU store load data(32) addr(32) addr match Flash/Program move RAM/variables addr match addr other

17 Getting numbers into registers you can use a mov instruction to put a small bit pattern into a register mov r4,#12 mov r5,#0x3a but you can't use a mov for a complex pattern mov r7,#0x20001c44 // <----not allowed you have two choices: move it in chunks mov r7,#0x orr r7,r7,#0x1c00 // r7=0x20001c00 orr r7,r7,#0x44 // r7=0x20001c44 or you can put the number nearby to your code, and do a ldr and use the PC (r15) to fetch it ldr r7,=0x20001c44 turns into ldr r7,[r15,#some_distance_away]

18 A common idiom for addressing One of the first things we have to do on the Cortex is turn on the various parts of the chip...in C RCC->APB2ENR = 0x74A3D;// enable zones a-d of gpio // the left hand side is at address 0x but you can't use a mov for a complex pattern mov r7,#0x // <----not allowed Here's now it could be done: movw r7,#0x orr r7,r7,#0x orr r7,r7,#0x18 movw r6,#0x4a3d orr r6,r6,#0x str r6,[r7] I don't recommend this style have a look at the next slide... // r7=0x // r7=0x // r6=0x00074a3d

19 A common idiom (cont'd)...literal mode Another way to do the same task uses the '=' prefix RCC->APB2ENR = 0x74A3D;// enable zones a-d of gpio // the left hand side is at address 0x can turn into ldr r7,=0x ldr r6,=0x74a3d str r6,[r7] what the assembler does: // just add the = in front // remember this is a LDR ldr r7,[pc,#0x14] // reach ahead into flash ldr r6,[pc,#0x18] str r6,[r7] // a gap.word 0x // this area is called the pool.word 0x00074a3d oddly, this is slightly slower code, but takes the least amount of flash, and is much easier to understand

20 A common idiom (cont'd)...movt Another third way to do the same task uses MOVT RCC->APB2ENR = 0x74A3D;// enable zones a-d of gpio // the left hand side is at address 0x can turn into movw r7,#0x1018 movt r7,#0x4002 movw r6,#0x4a3d movt r6,#0x7 str r6,[r7] // fill in the bottom half // is move into top // again, the bottom half // move into top of r6 in fact, this is the fastest version, but not quite so easy to understand

21 Putting it all together.text // we are creating program.global main // visible outside the obj file main: // a label to the symbol table mov r7, #0x ldr r6, [r7] // read ram@0x into r6 ldr r5, [r7, #4] // read the next word into r5 add r6, r5, r6 // add them str r6, [r7, #0x10] // store into the destination

22 Again, including the data.text // we are creating program.global main // visible outside the obj file main: // a label to the symbol table mov r7,#0x ldr r6, [r7] // read ram@0x into r6 ldr r5, [r7,#4] // read the other one into r5 add r6, r5, r6 // add str r6, [r7,#0x10] // store into the destination.data.word 0x // memory at 0x word 0x434 // at 0x org 0x10 // skip ahead to 0x word 0 // empty space for the answer

23 Again, using labels.text.global main main: // we are creating program // visible outside the obj file // a label to the symbol table ldr r7,=nstudentsontime ldr r6,[r7] // r6 = nstudentsontime ldr r5,[r7,#4] // r5 = nlatecomers add r6, r5, r6 // r6 = r5 + r6 str r6,[r7,#0x10] // ntotalstudents = r6.data // change ptr to 0x nstudentsontime:.word 12 nlatecomers:.word 4.org 0x10 // skip ahead to 0x ntotalstudents:.fill 2

24 Symbol Table while the assembler is running, it collects all the symbols into a symbol table this is just a spreadsheet with columns for name value type size

25 From the example name value type size main 0x label 0 nstudentsontime 0x word 4 nlatecomers 0x word 4 ntotalstudents 0x word 4

26 Symbol Table The symbol table converts human-readable names into machine-usable numbers it's an aid to humans; done correctly, it makes your code much more readable nnumberstudents.word 31 In a similar way, an DSN server converts humanreadable domain names into IP addresses An similarly, the paper telephone book helps you convert human-readble names into machine-readable phone numbers Pat Beirne

27 Example 2 write a program to delay by 40,000 loops

28 Example 2 write a program to delay by 40,000 loops.text.global delay40k delay40k: movw r5,#40000 // start with r5 set s1: subs r5, r5, #1 // sub 1, set flags bne s1 // if we're not done, loop

29 Example 3 modify example 2 to take exactly 1msec.text.global delaymsec delaymsec: movw r5,#2667 //each loop takes.375usec s1: subs r5, r5, #1 // sub 1 bne s1 // if we're not done, loop

30 Example 4 delay loop, using global variable.text.global delaysome delaysome: ldr r7, =delaytime ldr r6, [r7] delaymsec: movw r5,#2667 // each loop takes 0.375usec s1: subs r5, r5, #1 // sub 1 bne s1 // if we're not done, loop subs r6, r6, #1 bne delaymsec.data delaytime:.word 5 // the msec to delay

31 Symbol Table Name Value Type delaysome x (maybe 0x ) label delaymsec x+6 label s1 x+10 label delaytime y (maybe 0x ) short the symbol table here shows how it might look after the assembler, but before the linker

32 Example 5 write a snippet which does a checksum on a string of bytes the address of the string is in a variable the string count is in a variable and the string data is in another variable put the checksum into a 4 th variable char* stringaddr = mystring; char csum = 0; for (i=stringcount; i>0; i--) { csum += *stringaddr; stringaddr++; }

33 Example 5.data mystring:.ascii // credit card stringcount:.word 16 csum:.byte 0.text.global calcchecksum.type calcchecksum,%function calcchecksum: ldr r11, =mystring ldr r10, =stringcount ldr r12,[r10] // go to ram to get length mov r6, #0 // this will accumulate cs1: ldrb r4,[r11] // fetch and add to csum add r6, r4 add r11, #1 // point to next char subs r12, #1 // decrement & test bne cs1 ldr r10, =csum // and save the answer strb r6, [r10]

34 Symbol Table Example 5 Name Value Type Size Content calcchecksum x label;func 0 n/a cs1 x+0x0c label 0 n/a mystring y byte[] stringcount y+0x10 word 4 16=0x10 csum y+0x14 byte 1 the answer this symbol table shows how it might look after the assembler the assembler builds the opcodes, but leaves empty spots where the operands will go; the linker fills in the blanks from the symbol table

35 Symbol Table Example 5 Name Value Type Size Content calcchecksum 0x label;func 0 n/a cs1 0x label 0 n/a mystring 0x byte[] stringcount 0x word 4 16=0x10 csum 0x byte 1 the answer the addresses above show how the symbol table might look after the linker has finished; this example assumes there is no other code/data in the project the address for calcchecksum will get changed to 0x when it use stored as a word; that's what the %function operator does; remember that we're in a Thumb environment, and any LDR to r15 must be an odd number

36 Instruction Take Time each instruction takes a certain number of CPU cycles the boards we will use operate at 8 million cycles per second register-to-register operations take 1 jumps take 2 loads and stores use 2 if you push or pop n registers, it takes n+1 cycles mov r3, r3 takes 1 ldr r7, [r3] takes 2 push {r4, r5, r6} takes 4

37 Binary Math shift left by 1 same as multiply by 2 shift left by 4 0x14 (20 10 ) << 1 0x28 (40 10 ) << multiply by 16 shift right by 1 0x14 (20 10 ) << 4 0x140 ( ) << divide by 2 if it ends with a 1, it's odd 0x14 (20 10 ) >> 1 0x0A (10 10 ) >> ,3,5,7,9,b,d,f 0x21 = 0b = if it start with a 1, it's negative 0xFFFF.FFD1 =

38 Binary Math 2's complement flip all the bits and add 1 memorize these: 0xFFFF.FFFF = -1...FE = -2...FD = -3...FC = -4...F0 = -16 and these while you're at it, memorize these too: 0xA = xD = x14 = x40= xB = xE = x1E = x50= xC = xF = x28 = x64=100 10

39 Binary Math (8 bit) unsigned signed hex number line V B CA 28 C 28 1C BD C C BD DD 154 C A BD C 66 V 42 signed unsigned

40 Unsigned/Signed Math (16 bit) UNSIGNED two small numbers 4,660=0x ,328=0x ,988=0x88AC two large numbers 35,243=0x89AB 52,719=0xCDEF 87,962=0x1579A two very large numbers 65,244=0xFEDC 52,719=0xCDEF 117,963=0x1CCCB SIGNED small +ve, small +ve big +ve, big +ve small -ve, small -ve big -ve, big -ve small +ve, small -ve 4,660=0x ,136=0x ,796=0x68AC 4,660=0x ,328=0x ,988=0x88AC -292=0xFEDC -12,817=0xCDEF -13,109=0x1CCCB -30,293=0x89ab -12,817=0xCDEF -43,110=0x1579A 4,660=0x ,817=0xCDEF -8,157=0xE023

41 Why do we use 2's complement? 1's complement just flip the bits -2 0xFD -1 0xFE 0 0 or 0xFF (either) 1 0x01. suppose we do a few math calculations xFD + 0x03 = 0x01 (+1 signed) but if we treat 0xFD as unsigned (253)... then 0xFD+0x03 = 0x02 (with carry) xFD + 0xFD = 0xFB (-4 signed) but if we treat 0xFD as unsigned (254) then 0xFD+0xFD = 0xFA (with carry) try these again in 2's complement, they work just fine we would need a different adder for signed & unsigned

42 Why do we use 2's complement? 2's complement flip the bits and add one -2 0xFE even number -1 0xFF odd number x01. suppose we do a few math calculations xFE + 0x03 = 0x01 but if we treat 0xFE as unsigned (254)... then 0xFE+0x03 = 0x01 (with carry) xFD + 0xFD = 0xFA but if we treat 0xFD as unsigned (253) then 0xFD+0xFD = 0xFA (with carry) we can use the same adder for signed & unsigned we just need different overflow conditions: C & V

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

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

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

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

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018 ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018 (PRINT) Instructions: No calculators, books, or cell phones; do not communicate with any other student. One side of a single

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

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

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss Grundlagen Microcontroller Processor Core Günther Gridling Bettina Weiss 1 Processor Core Architecture Instruction Set Lecture Overview 2 Processor Core Architecture Computes things > ALU (Arithmetic Logic

More information

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2 Chapter 5 The LC-3 ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2 Instruction Set Architecture ISA = All of the programmer-visible components

More information

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison Introduction to Computer Engineering CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison Chapter 5 The LC-3 Announcements Homework 3 due today No class on Monday

More information

ECE251: Tuesday September 18

ECE251: Tuesday September 18 ECE251: Tuesday September 18 Subroutine Parameter Passing (Important) Allocating Memory in Subroutines (Important) Recursive Subroutines (Good to know) Debugging Hints Programming Hints Preview of I/O

More information

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture Introduction to Computer Engineering CS/ECE 252, Spring 200 Prof. David A. Wood Computer Sciences Department University of Wisconsin Madison Chapter 5 The LC-3 Adapted from Prof. Mark Hill s slides Instruction

More information

A Bit of History. Program Mem Data Memory. CPU (Central Processing Unit) I/O (Input/Output) Von Neumann Architecture. CPU (Central Processing Unit)

A Bit of History. Program Mem Data Memory. CPU (Central Processing Unit) I/O (Input/Output) Von Neumann Architecture. CPU (Central Processing Unit) Memory COncepts Address Contents Memory is divided into addressable units, each with an address (like an array with indices) Addressable units are usually larger than a bit, typically 8, 16, 32, or 64

More information

Computing Layers. Chapter 5 The LC-3

Computing Layers. Chapter 5 The LC-3 Computing Layers Problems Chapter 5 The LC-3 Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Algorithms Language Instruction

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

Instruction Set Architecture

Instruction Set Architecture Chapter 5 The LC-3 Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization address space -- how may locations can be addressed? addressibility

More information

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri Signed/Unsigned Integer Arithmetic in C Vineel Kovvuri http://vineelkovvuri.com Contents 1 Introduction 2 2 How signed-ness is represented in the hardware? 2 3 How signed-ness is interpreted in assembly?

More information

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA) CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA) Aleksandar Milenković Email: milenka@uah.edu Web: http://www.ece.uah.edu/~milenka Objective Introduce MSP430 Instruction Set Architecture (Class of ISA,

More information

Representation of Information

Representation of Information Representation of Information CS61, Lecture 2 Prof. Stephen Chong September 6, 2011 Announcements Assignment 1 released Posted on http://cs61.seas.harvard.edu/ Due one week from today, Tuesday 13 Sept

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

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison Introduction to Computer Engineering CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison Chapter 5 The LC-3 Instruction Set Architecture ISA = All of the

More information

Subroutines and the Stack

Subroutines and the Stack 3 31 Objectives: A subroutine is a reusable program module A main program can call or jump to the subroutine one or more times The stack is used in several ways when subroutines are called In this lab

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

ELEG3924 Microprocessor

ELEG3924 Microprocessor Department of Electrical Engineering University of Arkansas ELEG3924 Microprocessor Ch.2 Assembly Language Programming Dr. Jing Yang jingyang@uark.edu 1 OUTLINE Inside 8051 Introduction to assembly programming

More information

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

ELEG3923 Microprocessor Ch.2 Assembly Language Programming Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.2 Assembly Language Programming Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Inside 8051 Introduction to assembly programming

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

Advanced Assembly, Branching, and Monitor Utilities

Advanced Assembly, Branching, and Monitor Utilities 2 Advanced Assembly, Branching, and Monitor Utilities 2.1 Objectives: There are several different ways for an instruction to form effective addresses to acquire data, called addressing modes. One of these

More information

ARM ASSEMBLY PROGRAMMING

ARM ASSEMBLY PROGRAMMING ARM ASSEMBLY PROGRAMMING 1. part RAB Računalniška arhitektura 1 Intro lab : Addition in assembler Adding two variables : res := stev1 + stev2 Zbirni jezik Opis ukaza Strojni jezik ldr r1, stev1 R1 M[0x20]

More information

COSC121: Computer Systems: Review

COSC121: Computer Systems: Review COSC121: Computer Systems: Review Jeremy Bolton, PhD Assistant Teaching Professor Constructed using materials: - Patt and Patel Introduction to Computing Systems (2nd) - Patterson and Hennessy Computer

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

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

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

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers Chapter 5 The LC-3 Original slides from Gregory Byrd, North Carolina State University Modified slides by C. Wilcox, S. Rajopadhye Colorado State University Computing Layers Problems Algorithms Language

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

EEL 5722C Field-Programmable Gate Array Design

EEL 5722C Field-Programmable Gate Array Design EEL 5722C Field-Programmable Gate Array Design Lecture 12: Pipelined Processor Design and Implementation Prof. Mingjie Lin Patt and Patel: Intro. to Computing System * Stanford EE271 notes 1 Instruction

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

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

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

NET3001 Fall 12. Q1 Buttons & Lights: masking, branching, subroutine calls & globals

NET3001 Fall 12. Q1 Buttons & Lights: masking, branching, subroutine calls & globals NET3001 Fall 12 Assignment 2 Due: Sept 27, midnight Submitting: Use the submit.exe program. The files should be named assign21.s assign22.s In Eclipse, make a project for each, called assign21 and assign22.

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

Computer Organization CS 206 T Lec# 2: Instruction Sets

Computer Organization CS 206 T Lec# 2: Instruction Sets Computer Organization CS 206 T Lec# 2: Instruction Sets Topics What is an instruction set Elements of instruction Instruction Format Instruction types Types of operations Types of operand Addressing mode

More information

Mark II Aiken Relay Calculator

Mark II Aiken Relay Calculator Introduction to Embedded Microcomputer Systems Lecture 6.1 Mark II Aiken Relay Calculator 2.12. Tutorial 2. Arithmetic and logical operations format descriptions examples h 8-bit unsigned hexadecimal $00

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

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

COSC121: Computer Systems: Review

COSC121: Computer Systems: Review COSC121: Computer Systems: Review Jeremy Bolton, PhD Assistant Teaching Professor Constructed using materials: - Patt and Patel Introduction to Computing Systems (2nd) - Patterson and Hennessy Computer

More information

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING CHAPTER 2 8051 ASSEMBLY LANGUAGE PROGRAMMING Registers Register are used to store information temporarily: A byte of data to be processed An address pointing to the data to be fetched The vast majority

More information

Developing StrongARM/Linux shellcode

Developing StrongARM/Linux shellcode Into my ARMs Developing StrongARM/Linux shellcode by funkysh 16.12.2001 ----{ Introduction This paper covers informations needed to write StrongARM Linux shellcode. All examples presented

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

UW CSE 351, Winter 2013 Midterm Exam

UW CSE 351, Winter 2013 Midterm Exam Full Name: Student ID: UW CSE 351, Winter 2013 Midterm Exam February 15, 2013 Instructions: Make sure that your exam is not missing any of the 9 pages, then write your full name and UW student ID on the

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1

More information

When an instruction is initially read from memory it goes to the Instruction register.

When an instruction is initially read from memory it goes to the Instruction register. CS 320 Ch. 12 Instruction Sets Computer instructions are written in mnemonics. Mnemonics typically have a 1 to 1 correspondence between a mnemonic and the machine code. Mnemonics are the assembly language

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

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label sarm User Guide The sarm is program that implements an experimental CPU simulator. It is called experimental because it is not yet complete, and it also incorporates facilities that are not conventionally

More information

Machine Language, Assemblers and Linkers"

Machine Language, Assemblers and Linkers Machine Language, Assemblers and Linkers 1 Goals for this Lecture Help you to learn about: IA-32 machine language The assembly and linking processes 2 1 Why Learn Machine Language Last stop on the language

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

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

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1 CSIS1120A 10. Instruction Set & Addressing Mode CSIS1120A 10. Instruction Set & Addressing Mode 1 Elements of a Machine Instruction Operation Code specifies the operation to be performed, e.g. ADD, SUB

More information

Bitwise Instructions

Bitwise Instructions Bitwise Instructions CSE 30: Computer Organization and Systems Programming Dept. of Computer Science and Engineering University of California, San Diego Overview v Bitwise Instructions v Shifts and Rotates

More information

LAB 1 Using Visual Emulator. Download the emulator https://salmanarif.bitbucket.io/visual/downloads.html Answer to questions (Q)

LAB 1 Using Visual Emulator. Download the emulator https://salmanarif.bitbucket.io/visual/downloads.html Answer to questions (Q) LAB 1 Using Visual Emulator Download the emulator https://salmanarif.bitbucket.io/visual/downloads.html Answer to questions (Q) Load the following Program in Visual Emulator ; The purpose of this program

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

CSCI 2212: Intermediate Programming / C Chapter 15

CSCI 2212: Intermediate Programming / C Chapter 15 ... /34 CSCI 222: Intermediate Programming / C Chapter 5 Alice E. Fischer October 9 and 2, 25 ... 2/34 Outline Integer Representations Binary Integers Integer Types Bit Operations Applying Bit Operations

More information

Chapter 1 Microprocessor architecture ECE 3120 Dr. Mohamed Mahmoud http://iweb.tntech.edu/mmahmoud/ mmahmoud@tntech.edu Outline 1.1 Computer hardware organization 1.1.1 Number System 1.1.2 Computer hardware

More information

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor CS 261 Fall 2018 0000000100000f50 55 48 89 e5 48 83 ec 10 48 8d 3d 3b 00 00 00 c7 0000000100000f60 45 fc 00 00 00 00 b0 00 e8 0d 00 00 00 31 c9 89 0000000100000f70 45 f8 89 c8 48 83 c4 10 5d c3 Mike Lam,

More information

Survey. Motivation 29.5 / 40 class is required

Survey. Motivation 29.5 / 40 class is required Survey Motivation 29.5 / 40 class is required Concerns 6 / 40 not good at examination That s why we have 3 examinations 6 / 40 this class sounds difficult 8 / 40 understand the instructor Want class to

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

Instruction Sets: Characteristics and Functions Addressing Modes

Instruction Sets: Characteristics and Functions Addressing Modes Instruction Sets: Characteristics and Functions Addressing Modes Chapters 10 and 11, William Stallings Computer Organization and Architecture 7 th Edition What is an Instruction Set? The complete collection

More information

CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART

CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART General Introduction CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART 1) General Introduction (1/5): On Instructions Instruction operate with data or with the flow of the program The following information

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

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

CS 241 Data Organization Binary

CS 241 Data Organization Binary CS 241 Data Organization Binary Brooke Chenoweth University of New Mexico Fall 2017 Combinations and Permutations In English we use the word combination loosely, without thinking if the order of things

More information

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set? COMP 212 Computer Organization & Architecture Quiz COMP 212 Fall 2008 Lecture 7 Fill in your student number only, do NOT write down your name Open book, but NO calculator, NO discussions, Relax and have

More information

11. A Computing Machine

11. A Computing Machine COMPUTER SCIENCE S E D G E W I C K / W A Y N E Computer Science Including Programming in Java 11. A Computing Machine Section 5.1 http://introcs.cs.princeton.edu COMPUTER SCIENCE S E D G E W I C K / W

More information

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA) COMP2121: Microprocessors and Interfacing Instruction Set Architecture (ISA) http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 Contents Memory models Registers Data types Instructions

More information

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

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown

More information

ARM Assembler Workbook. CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005

ARM Assembler Workbook. CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005 ARM Assembler Workbook CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005 ARM University Program Version 1.0 January 14th, 1997 Introduction Aim This workbook provides the student

More information

Introduction to Computer. Chapter 5 The LC-3. Instruction Set Architecture

Introduction to Computer. Chapter 5 The LC-3. Instruction Set Architecture Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin Madison Chapter 5 The LC-3 Instruction Set Architecture

More information

Technical Specification. Third Party Control Protocol. AV Revolution

Technical Specification. Third Party Control Protocol. AV Revolution Technical Specification Third Party Control Protocol AV Revolution Document AM-TS-120308 Version 1.0 Page 1 of 31 DOCUMENT DETAILS Document Title: Technical Specification, Third Party Control Protocol,

More information

Assembly Language. CS2253 Owen Kaser, UNBSJ

Assembly Language. CS2253 Owen Kaser, UNBSJ Assembly Language CS2253 Owen Kaser, UNBSJ Assembly Language Some insane machine-code programming Assembly language as an alternative Assembler directives Mnemonics for instructions Machine-Code Programming

More information

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1 Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD 21252 rkarne@towson.edu 11/12/2014 Slide 1 Intel x86 Aseembly Language Assembly Language Assembly Language

More information

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

More information

Microcontroller Systems

Microcontroller Systems µcontroller systems 1 / 43 Microcontroller Systems Engineering Science 2nd year A2 Lectures Prof David Murray david.murray@eng.ox.ac.uk www.robots.ox.ac.uk/ dwm/courses/2co Michaelmas 2014 µcontroller

More information

Assembly Language Programming

Assembly Language Programming Experiment 3 Assembly Language Programming Every computer, no matter how simple or complex, has a microprocessor that manages the computer s arithmetical, logical and control activities. A computer program

More information

ECE 206, Fall 2001: Lab 3

ECE 206, Fall 2001: Lab 3 ECE 206, : Lab 3 Data Movement Instructions Learning Objectives This lab will give you practice with a number of LC-2 programming constructs. In particular you will cover the following topics: - Load/store

More information

This simulated machine consists of four registers that will be represented in your software with four global variables.

This simulated machine consists of four registers that will be represented in your software with four global variables. CSCI 4717 Computer Architecture Project 1: Two-Stage Instuction Decoder Due: Monday, September 21, 26 at 11:59 PM What to submit: You will be submitting a text file containing two C functions, fetchnextinstruction()

More information

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification Application Note 3/2003 PC Master Software Communication Protocol Specification By Pavel Kania and Michal Hanak S 3 L Applications Engineerings MCSL Roznov pod Radhostem Introduction The purpose of this

More information

CS/ECE 5780/6780: Embedded System Design

CS/ECE 5780/6780: Embedded System Design CS/ECE 5780/6780: Embedded System Design John Regehr Lecture 2: 68HC12 Architecture & Lab 1 Introduction Duff s Device void foo (int x, int *y, int *z) { switch (x % 8) { case 0: do { *y++ = *z++; case

More information

For all questions, please show your step-by-step solution to get full-credits.

For all questions, please show your step-by-step solution to get full-credits. For all questions, please show your step-by-step solution to get full-credits. Question 1: Assume a 5 stages microprocessor, calculate the number of cycles of below instructions for 1) no pipeline system

More information

LC-3 Instruction Set Architecture. Textbook Chapter 5

LC-3 Instruction Set Architecture. Textbook Chapter 5 LC-3 Instruction Set Architecture Textbook Chapter 5 Instruction set architecture What is an instruction set architecture (ISA)? It is all of the programmer-visible components and operations of the computer

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

17.1. Unit 17. Instruction Sets Picoblaze Processor

17.1. Unit 17. Instruction Sets Picoblaze Processor 17.1 Unit 17 Instruction Sets Picoblaze Processor INSTRUCTION SET OVERVIEW 17.2 17.3 Instruction Set Review Defines the software interface of the processor and memory system Instruction set is the vocabulary

More information

C++ to assembly to machine code

C++ to assembly to machine code IBCM 1 C++ to assembly to machine code hello.cpp #include int main() { std::cout

More information

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition BASIC COMPUTER ORGANIZATION Silberschatz, Galvin and Gagne 2009 Topics CPU Structure Registers Memory Hierarchy (L1/L2/L3/RAM) Machine Language Assembly Language Running Process 3.2 Silberschatz, Galvin

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

Binary Arithmetic Intro to Assembly Language CS 64: Computer Organization and Design Logic Lecture #3

Binary Arithmetic Intro to Assembly Language CS 64: Computer Organization and Design Logic Lecture #3 Binary Arithmetic Intro to Assembly Language CS 64: Computer Organization and Design Logic Lecture #3 Ziad Matni Dept. of Computer Science, UCSB Adding this Class The class is full I will not be adding

More information

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off. Department of Electrical and Computer Engineering University of Wisconsin Madison ECE 552 Introductions to Computer Architecture Homework #2 (Suggested Solution) 1. (10 points) MIPS and C program translations

More information

Microcontroller Architecture and Interfacing HOMEWORK 3

Microcontroller Architecture and Interfacing HOMEWORK 3 CSE/EE 5/7385 Microcontroller Architecture and Interfacing HOMEWORK 3 1. Assume the following values are signed ARM halfwords. Calculate their value in decimal (radix- 10) and show all your work. a) 0xFEED

More information

Machine and Assembly Language Principles

Machine and Assembly Language Principles Machine and Assembly Language Principles Assembly language instruction is synonymous with a machine instruction. Therefore, need to understand machine instructions and on what they operate - the architecture.

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