COMP3221: Microprocessors and Embedded Systems

Size: px
Start display at page:

Download "COMP3221: Microprocessors and Embedded Systems"

Transcription

1 Embedded ystems Overview Arithmetic and Logic nstructions in AR ample AR Assembly Programs Using AL instructions Lecture 7: Arithmetic and logic nstructions Lecturer: ui Wu ession 2, AR nstruction Overview General-Purpose Registers in AR Load/store architecture At most two operands in each instruction Most instructions are two bytes long ome instructions are 4 bytes long Four ategories: Arithmetic and logic instructions Program control instruction Data transfer instruction Bit and bit test instructions 32 general-purpose registers named r0, r1,, r31 in AR assembly language Broken into two parts: with 16 registers each, r0 to r15 and r16 to r31. Each register is also assigned a memory address in RAM space. Register r0 and r26 through r31 have additional functions. o r0 is used in the instruction LPM (load program memory) o Registers x (r27 : r26), y (r29 : r28) and z (r31 : r30) are used as pointer registers Most instructions that operate on the registers have direct, single cycle access to all general registers. ome instructions such as sbci, subi, cpi, andi, ori and ldi operates only on a subset of registers. 3 4

2 General-Purpose Registers in AR (ont.) Address 0x00 r0 0x01 r1 he tatus Register in AR he tatus Register (REG) contains information about the result of the most recently executed arithmetic instruction. his information can be used for altering program flow in order to perform conditional operations. 0x1A 0x1B 0x1 0x1D r26 r27 r28 r29 x register low byte x register high byte y register low byte y register high byte REG is updated after all ALU operations. REG is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. his must be handled by software. 0x1E r30 z register low byte 0x1F r31 z register high byte 5 6 he tatus Register in AR (ont.) he tatus Register in AR (ont.) Bit 7 : Global nterrupt Enable Used to enable and disable interrupts. 1: enabled. 0: disabled. he -bit is cleared by hardware after an interrupt has occurred, and is set by the RE instruction to enable subsequent interrupts. Bit 6 : Bit opy torage he Bit opy instructions BLD (Bit LoaD) and B (Bit ore) use the -bit as source or destination for the operated bit. A bit from a register in the Register File can be copied into by the B instruction, and a bit in can be copied into a bit in a register in the Register File by the BLD instruction. 7 8

3 he tatus Register in AR (ont.) he tatus Register in AR (ont.) Bit 5 : alf arry Flag he alf arry Flag indicates a alf arry (carry from bit 4) in some arithmetic operations. alf arry is useful in BD arithmetic. Bit 4 : ign Bit Exclusive OR between the egative Flag and the wo s omplement Overflow Flag ( = ). Bit 3 : wo s omplement Overflow Flag he wo s omplement Overflow Flag supports two s complement arithmetic he tatus Register in AR (ont.) he tatus Register in AR (ont.) Bit 2 : egative Flag is the most significant bit of the result. Bit 1 : ero Flag indicates a zero result in an arithmetic or logic operation. 1: zero. 0: on-zero. 11 Bit 0 : arry Flag ts meaning depends on the operation. For addition X+Y, it is the carry from the most significant bit. n other words, = Rd7 Rr7 +Rr7 O(R7) + O(R7) Rd7, where Rd7 is bit 7 of x, Rr7 is bit 7 of y, R7 is bit 7 of x+y, is the logical AD and + is the logical OR. For subtraction x-y, where x and y are unsigned integer, it indicates if x<y. f x<y, the =1; otherwise, =0. n other words, = O(Rd7) Rr7+ Rr7 R7 +R7 O(Rd7). 12

4 elected Arithmetic and Logic nstructions add, adc, inc sub, sbc, dec mul, muls, mulsu and, or, eor clr, cbr, cp, cpc, cpi, tst com, neg Refer to the main textbook (Pages 63~67) and AR nstruction et for the complete list of AL instructions. yntax: add Rd, Rr Add without arry Operation: Rd Rd + Rr Encoding: rd dddd rrrr add r1, r2 ; Add r2 to r1 add r28, r28 ; Add r28 to itself Add with arry ncrement yntax: inc Rd yntax: adc Rd, Rr Operation: Rd Rd + Rr + Encoding: rd dddd rrrr Add r1 : r0 to r3 : r2 add r2, r0 ; Add low byte adc r3, r1 ; Add high byte omments: adc is used in multi-byte addition. Operation: Rd Rd+1 Flags affected:,,, Encoding: d dddd 1011 clr r22 ; clear r22 loop: inc r22 ; ncrement r22 cpi r22, $4F ; compare r22 to $4F brne loop ; Branch to loop if not equal nop ; ontinue (do nothing 15 16

5 ubtract without arry ubtract with arry yntax: sub Rd, Rr yntax: sbc Rd, Rr Operation: Rd Rd Rr Encoding: rd dddd rrrr sub r13, r12 ; ubtract r12 from r13 Operation: Rd Rd Rr Encoding: rd dddd rrrr ubtract r1:r0 from r3:r2 sub r2, r0 ; ubtract low byte sbc r3, r1 ; ubtract with carry high byte omments: sbc is used in multi-byte subtraction Decrement Multiply Unsigned yntax: dec Rd yntax: mul Rd, Rr Operation: Rd Rd 1 Encoding: d dddd 1010 ldi r17, $10 ; Load constant in r17 Operation: r1, r0 Rr*Rd (unsigned unsigned * unsigned ) Flags affected:, Encoding: rd dddd rrrr ycles: 2 mul r6, r5 ; Multiply r6 and r5 loop: add r1, r2 ; Add r2 to r1 mov r6, r1 dec r17 ; Decrement r17 mov r5, r0 ; opy result back in r6 : r5 brne loop; ; Branch to loop if r17 0 nop ; ontinue (do nothing) 19 20

6 Multiply igned Multiply igned with Unsigned yntax: muls Rd, Rr Operands: Rd, Rr {r16, r17,, r31} Operation: r1, r0 Rr*Rd (signed signed * signed ) Flags affected:, Encoding: dddd rrrr ycles: 2 mul r17, r16 ; Multiply r17 and r16 movw r17:r16, r1:r0 ; opy result back to r17 : r16 yntax: mulsu Rd, Rr Operands: Rd, Rr {r16, r17,, r23} Operation: r1, r0 Rr*Rd (signed signed * unsigned ) Flags affected:, is set if bit 15 of the result is set; cleared otherwise. Encoding: ddd 0rrr ycles: Multiply igned with Unsigned (ont.) Example: igned multiply of two 16-bit numbers stored in r23:r22 and r21:r20 with 32-bit result stored in r19:r18:r17:r16 ow to do? Let ah and al be the high byte and low byte, respectively, of the multiplicand and bh and bb the high byte and low byte, respectively, of the multiplier. ah : al * bh : bl = (ah* al) * (bh* 2 8 +bl) = ah*bh* al*bh* ah*bl*2 8 + al*bl 23 Multiply igned with Unsigned (ont.) Example: igned multiply of two 16-bit numbers stored in r23:r22 and r21:r20 with 32-bit result stored in r19:r18:r17:r16 muls16x16_32: clr r2 muls r23, r21 ; (signed) ah * (signed) bh movw r19 : r18, r1 : r0 mul r22, r20 ; (unsigned) al * (unsigned) bl movw r17 : r16, r1: r0 mulsu r23, r20 ; (signed) ah * (unsigned) bl sbc r19, r2 ; rick here (int: what does the carry mean here?) add r17, r0 adc r18, r1 adc r19, r2 mulsu r21, r22 sbc r19, r2 ; rick here add r17, r0 adc r18, r1 adc r19, r2 ret ; (signed) bh * (unsigned) al 24

7 Lower-ase to Upper-ase.include "m64def.inc".equ size =5.def counter =r17.dseg.org 0x100 ; et the starting address of data segment to 0x100 ap_string:.byte 5.cseg Low_string:.db "hello" ldi zl, low(low_string<<1) ; Get the low byte of the address of "h" ldi zh, high(low_string<<1) ; Get the high byte of the address of "h" ldi yh, high(ap_string) ldi yl, low(ap_string) clr counter ; counter=0 25 main: Lower-ase to Upper-ase (ont.) loop: nop lpm r20, z+ ; Load a letter from flash memory subi r20, 32 ; onvert it to the capital letter st y+,r20 ; tore the capital letter in RAM inc counter cpi counter, size brlt main rjmp loop 26 Bitwise AD Bitwise OR yntax: and Rd, Rr Operation: Rd Rr Rd (Bitwise AD Rr and Rd) Encoding: rd dddd rrrr ldi r2, 0b ldi r16, 1 and r2, r16 ; r2=0b yntax: or Rd, Rr Operation: Rd Rr v Rd (Bitwise OR Rr and Rd) Encoding: rd dddd rrrr ldi r15, 0b ldi r16, 0b or r15, r16 ; Do bitwise or between registers ; r15=0b

8 Bitwise Exclusive-OR lear Bits in Register yntax: eor Rd, Rr Operation: Rd Rr Rd (Bitwise exclusive OR Rr and Rd) Encoding: rd dddd rrrr eor r4, r4 ; lear r4 eor r0, r22 ; Bitwise exclusive or between r0 and r22 ; f r0=0b and r22=0b ; then r0=0b yntax: cbr Rd, k Operands: Rd {r16, r17,, r31} and 0 k 255 Operation: Rd Rd ($FF-k) (lear the bits specified by k ) Encoding: 0111 wwww dddd wwww (wwwwwwww=$ff-k) cbr r4, 11 ; lear bits 0 and 1 of r ompare ompare with arry yntax: cp Rd, Rr Operation: Rd Rr (Rd is not changed) Encoding: rd dddd rrrr cp r4, r5 brne noteq... noteq: nop ; ompare r4 with r5 ; Branch if r4 r5 ; Branch destination (do nothing) yntax: cpc Rd, Rr Operation: Rd Rr (Rd is not changed) Encoding: rd dddd rrrr ; ompare r3:r2 with r1:r0 cp r2, r0 ; ompare low byte cpc r3, r1 ; ompare high byte brne noteq ; Branch if not equal... noteq: nop ; Branch destination (do nothing) 31 32

9 ompare with mmediate est for ero or Minus yntax: cpi Rd, k Operands: Rd {r16, r17,, r31} and 0 k 255 Operation: Rd k (Rd is not changed) Encoding: 0011 kkkk dddd kkkk cp r19, 30 ; ompare r19 with 30 brne noteq ; Branch if r noteq: nop ; Branch destination (do nothing) yntax: tst Rd Operation: Rd Rd Rd Encoding: dd dddd dddd tst r0 ; est r0 breq zero ; Branch if r0=0... zero: nop ; Branch destination (do nothing) One's omplement wo's omplement yntax: com Rd Operation: Rd $FF Rd Encoding: d dddd 0000 com r4 breq zero... zero: nop ; ake one's complement of r4 ; Branch if zero ; Branch destination (do nothing) 35 yntax: neg Rd Operation: Rd $00 Rd (he value of $80 is left unchanged) : R3 + Rd3 et if there is a borrow from bit 3; cleared otherwise Encoding: d dddd 0001 sub r11,r0 ;ubtract r0 from r11 brpl positive ;Branch if result positive neg r11 ;ake two's complement of r11 positive: nop ;Branch destination (do nothing) 36

10 Reading Material 1. AR nstruction et. 37

COMP2121: Microprocessors and Interfacing

COMP2121: Microprocessors and Interfacing nterfacing Overview Arithmetic and Logic nstructions in AR ample AR Assembly Programs Using AL instructions Lecture 8: Arithmetic and logic nstructions http://www.cse.unsw.edu.au/~cs2121 Lecturer: ui Wu

More information

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation 2 Atmel AVR 8-bit RISC architecture

More information

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation 2 Atmel AVR 8-bit RISC architecture

More information

AVR ISA & AVR Programming (I)

AVR ISA & AVR Programming (I) AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo Week 1 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation Week 1 2 1 Atmel AVR 8-bit

More information

COMP2121: Microprocessors and Interfacing. AVR Assembly Programming (I) Basic AVR Instructions

COMP2121: Microprocessors and Interfacing. AVR Assembly Programming (I) Basic AVR Instructions COMP2121: Microprocessors and Interfacing AVR Assembly Programming (I) Basic AVR Instructions http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Contents Arithmetic and Logic Instructions

More information

By: Dr. Hamed Saghaei

By: Dr. Hamed Saghaei By: Dr. Hamed Saghaei The AVR RISC Microcontroller supports powerful and efficient addressing modes for access to the program memory (Flash) and data memory (SRAM). This section describes the different

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

APPENDIX B AVR INSTRUCTIONS EXPLAINED OVERVIEW

APPENDIX B AVR INSTRUCTIONS EXPLAINED OVERVIEW APPENDIX B AVR INSTRUCTIONS EXPLAINED OVERVIEW In this appendix, we describe each intruction of the ATmega328. In many cases, a simple code example is given to clarify the instruction. Instructions are

More information

8-bit Instruction Set

8-bit Instruction Set Instruction Set Nomenclature Status Register (SREG) SREG: Status Register C: Carry Flag Z: Zero Flag N: Negative Flag V: Two s complement overflow indicator S: N V, For signed tests H: Half Carry Flag

More information

COMP2121: Microprocessors and Interfacing

COMP2121: Microprocessors and Interfacing Interfacing Lecture 9: Program Control Instructions http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 1, 2006 Program control instructions in AVR Stacks Overview Sample AVR assembly programs

More information

8-bit Instruction Set

8-bit Instruction Set Instruction Set Nomenclature Status Register (SREG) SREG: Status Register C: Carry Flag Z: Zero Flag N: Negative Flag V: Two s complement overflow indicator S: N V, For signed tests H: Half Carry Flag

More information

CN310 Microprocessor Systems Design

CN310 Microprocessor Systems Design CN310 Microprocessor Systems Design Instruction Set (AVR) Nawin Somyat Department of Electrical and Computer Engineering Thammasat University Outline Course Contents 1 Introduction 2 Simple Computer 3

More information

AVR Instruction Set Encoding

AVR Instruction Set Encoding 1 P age AVR Instruction Set Encoding READING 1. "AVR Instruction Set" document doc856 "The Program and Data Addressing Modes." 2. In this lecture I will teach you how to translate your assembly code into

More information

BASIC AVR ARITHMATIC v1.1 ADDITION and SUBTRACTION by

BASIC AVR ARITHMATIC v1.1 ADDITION and SUBTRACTION by BASIC AVR ARITHMATIC v1.1 ADDITION and SUBTRACTION by RetroDan@GMail.Com CONTENTS: 1. ADDING AND SUBTRACTING ONE FROM A REGISTER 2. LOADING A REGISTER WITH A CONSTANT 3. ADDING AND SUBTRACTING A CONSTANT

More information

AT90S Bit Microcontroller with 1K bytes Downloadable Flash AT90S1200. Features. Description. Pin Configuration

AT90S Bit Microcontroller with 1K bytes Downloadable Flash AT90S1200. Features. Description. Pin Configuration Features Utilizes the AVR Enhanced RISC Architecture 89 Powerful Instructions - Most Single Clock Cycle Execution 1K bytes of In-System Reprogrammable Downloadable Flash - SPI Serial Interface for Program

More information

Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming

Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming Prof. Ben Lee Oregon State University School of Electrical Engineering and Computer Science Chapter Goals Understand how to program

More information

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD A. Assembly Language Programming Programming of a computer system: Machine code direct execution Assembly language tool: assembler High level programming language tool: interpreter tool: compiler Programming

More information

;Compiler Options.NOLIST.INCLUDE "C:\Program Files (x86)\atmel\avr Tools\AvrAssembler2\Appnotes\m8515def.inc"

;Compiler Options.NOLIST.INCLUDE C:\Program Files (x86)\atmel\avr Tools\AvrAssembler2\Appnotes\m8515def.inc ;* CharTest.asm ;* ;* Created: 28/06/2017 9:37 p.m. ;* Author: ob1 ;ST7820 128 x 64 graphics mode character display 8 lines x 21 characters ;Modification and redistribution under provisions of GNU general

More information

AVR Logical and Bitwise Instructions

AVR Logical and Bitwise Instructions AVR Logical and Bitwise Instructions Assembly Language Programming SDSMT Dr. Randy C. Hoover Boolean Logic An algebraic system for Boolean data Set: {false, true) Operations: and, or, not The operations

More information

COMP3221: Microprocessors and Embedded Systems. Lecture 11: Assembly Lecturer: Hui Wu Session 2, 2005

COMP3221: Microprocessors and Embedded Systems. Lecture 11: Assembly  Lecturer: Hui Wu Session 2, 2005 COMP3221: Microprocessors and Embedded Systems Lecture 11: Assembly http://www.cse.unsw.edu.au/~cs3221 Lecturer: Hui Wu Session 2, 2005 Overview Pseudo Instructions Macro Assembly Process 2 Assembly Language

More information

University of Florida EEL 4744 Dr. Eric M. Schwartz. Page 1/11 Revision 0 20-Feb-14 Mixed C and Assembly (for Atmel XMEGA)

University of Florida EEL 4744 Dr. Eric M. Schwartz. Page 1/11 Revision 0 20-Feb-14 Mixed C and Assembly (for Atmel XMEGA) Page 1/11 Revision 0 20-Feb-14 KEY WORDS Compiler, Inline Assembly, GNU Assembler, GCC, AVR-GCC RESOURCES GNU Assembler Resource - http://sourceware.org/binutils/docs-2.23.1/as/index.html AVR-LibC Inline

More information

Basic ARM InstructionS

Basic ARM InstructionS Basic ARM InstructionS Instructions include various fields that encode combinations of Opcodes and arguments special fields enable extended functions (more in a minute) several 4-bit OPERAND fields, for

More information

EE 308: Microcontrollers

EE 308: Microcontrollers EE 308: Microcontrollers Assmbly Language Part I Aly El-Osery Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA January 30, 2018 Aly El-Osery (NMT)

More information

ATmega128 Assembly Language Programming

ATmega128 Assembly Language Programming 마이크로프로세서응용 7 ATmega128 Assembly Language Programming Assembly Language g Field Delimiter Field structure a space or colon after a label a space after the operation code a comma between operands in the

More information

Microcontroller. Instruction set of 8051

Microcontroller. Instruction set of 8051 UNIT 2: Addressing Modes and Operations: Introduction, Addressing modes, External data Moves, Code Memory, Read Only Data Moves / Indexed Addressing mode, PUSH and POP Opcodes, Data exchanges, Example

More information

Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices

Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices Kostas Papagiannopoulos Aram Verstegen July 11, 2013 Papagiannopoulos and Verstegen July 11, 2013 Speed and Size-Optimized

More information

COMP2121: Microprocessors and Interfacing. Instruction Formats and Addressing Modes

COMP2121: Microprocessors and Interfacing. Instruction Formats and Addressing Modes COMP2121: Microprocessors and Interfacing Instruction Formats and Addressing Modes http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Instruction format AVR instruction format

More information

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu 1 Lecture overview Stack and stack operations Functions and function calls Calling conventions 2 Stack What is stack?

More information

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now) 18 100 Lecture 20: AVR Programming, Continued S 15 L20 1 James C. Hoe Dept of ECE, CMU April 2, 2015 Today s Goal: You will all be ace AVR hackers! Announcements: Midterm 2 can be picked up in lab and

More information

Logic Instructions and Programs READING

Logic Instructions and Programs READING 1 P a g e Logic Instructions and Programs READING The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi Chapter 5: Arithmetic, Logic

More information

Addressing Modes Part II AVR Addressing Indirect READING

Addressing Modes Part II AVR Addressing Indirect READING 1 P a g e Addressing Modes Part II AVR Addressing Indirect READING The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi Chapter 6: AVR

More information

8-Bit Microcontroller with 1K bytes In-System Programmable Flash AT90S1200. Features. Description. Pin Configuration

8-Bit Microcontroller with 1K bytes In-System Programmable Flash AT90S1200. Features. Description. Pin Configuration Features AVR - High Performance and Low Power RISC Architecture 89 Powerful Instructions - Most Single Clock Cycle Execution 1K bytes of In-System Reprogrammable Flash SPI Serial Interface for Program

More information

Gates and flip-flops: glue logic, simple FSMs, registers Two-level PLDs: FSMs, muxes, decoders. Programmable logic devices (CSE370, CSE467)

Gates and flip-flops: glue logic, simple FSMs, registers Two-level PLDs: FSMs, muxes, decoders. Programmable logic devices (CSE370, CSE467) Computational hardware Digital logic (CSE370) Gates and flip-flops: glue logic, simple FSMs, registers Two-level PLDs: FSMs, muxes, decoders Programmable logic devices (CSE370, CSE467) Field-programmable

More information

ST6 FAMILY PROGRAMMING MANUAL

ST6 FAMILY PROGRAMMING MANUAL ST6 FAMILY PROGRAMMING MANUAL Rev. 2.0 October 2004 1 PROGRAMMING MANUAL ST6 FAMILY INTRODUTION This manual deals with the description of the instruction set and addressing modes of ST6 microcontroller

More information

Assembly Programming (III)

Assembly Programming (III) Assembly Programming (III) Lecturer: Annie Guo S2, 2006 COMP9032 Week6 1 Lecture Overview Stack and stack operations Functions and function calls Calling conventions S2, 2006 COMP9032 Week6 2 What is stack?

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

Building A RISC Microcontroller in an FPGA. Yap Zi He

Building A RISC Microcontroller in an FPGA. Yap Zi He Building A RISC Microcontroller in an FPGA Yap Zi He yapzihe@hotmail.com http://www.opencores.org/projects/riscmcu/ Supervisor : Muhammad Mun im Ahmad Zabidi (Assoc Prof) raden@utm.my Faculty of Electrical

More information

ก AVR Microcontrollers

ก AVR Microcontrollers ก AVR Microcontrollers. ก ก AVR Microcontrollers Architecture 1 Instruction Execution Timing The Parallel Instruction Fetches and Instruction Executions Single Cycle ALU Operation AVR Microcontrollers

More information

AVR Control Transfer -AVR Branching

AVR Control Transfer -AVR Branching 1 P a g e AVR Control Transfer -AVR Branching Reading The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi Chapter 3: Branch, Call,

More information

The Assembly Language of the Boz 5

The Assembly Language of the Boz 5 The Assembly Language of the Boz 5 The Boz 5 uses bits 31 27 of the IR as a five bit opcode. Of the possible 32 opcodes, only 26 are implemented. Op-Code Mnemonic Description 00000 HLT Halt the Computer

More information

8051 Overview and Instruction Set

8051 Overview and Instruction Set 8051 Overview and Instruction Set Curtis A. Nelson Engr 355 1 Microprocessors vs. Microcontrollers Microprocessors are single-chip CPUs used in microcomputers Microcontrollers and microprocessors are different

More information

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function Module 8: Atmega32 Stack & Subroutine Stack Pointer Subroutine Call function Stack Stack o Stack is a section of RAM used by the CPU to store information temporarily (i.e. data or address). o The CPU needs

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

68HC11 PROGRAMMER'S MODEL

68HC11 PROGRAMMER'S MODEL 8H11 PROGRMMER'S MODEL s (,, and D) s and are general-purpose 8-bit accumulators used to hold operands and results of arithmetic calculations or data manipulations. Some instructions treat the combination

More information

Assembly Programming (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

Assembly Programming (II) Lecturer: Sri Parameswaran Notes by: Annie Guo Assembly Programming (II) Lecturer: Sri Parameswaran Notes by: Annie Guo 1 Lecture overview Assembly program structure Assembler directives Assembler expressions Macro Memory access Assembly process First

More information

1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M. 2 PUSH/ POP R16/M16/SR/F 2 x ( ) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M

1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M. 2 PUSH/ POP R16/M16/SR/F 2 x ( ) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M Increment R16 1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M 4 x (16+48) = 256 opcodes 2 PUSH/ POP R16/M16/SR/F 2 x (8+24+4+1) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M 4 x (16+48) = 256 opcodes INC

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

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory Today s Menu Methods >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory Look into my See examples on web-site: ParamPassing*asm and see Methods in Software and

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

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

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

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2 ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Set #2 1- Consider the internal structure of the pseudo-cpu discussed in class augmented with a single-port register file (i.e.,

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

INSTRUCTION SET OF 8085

INSTRUCTION SET OF 8085 INSTRUCTION SET OF 8085 Instruction Set of 8085 An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor

More information

Microcontroller Intel [Instruction Set]

Microcontroller Intel [Instruction Set] Microcontroller Intel 8051 [Instruction Set] Structure of Assembly Language [ label: ] mnemonic [operands] [ ;comment ] Example: MOV R1, #25H ; load data 25H into R1 2 8051 Assembly Language Registers

More information

Contents 8051 Instruction Set BY D. BALAKRISHNA, Research Assistant, IIIT-H Chapter I : Control Transfer Instructions Lesson (a): Loop Lesson (b): Jump (i) Conditional Lesson (c): Lesson (d): Lesson (e):

More information

LEO-1 Homebrew Computer

LEO-1 Homebrew Computer LEO-1 Homebrew Computer Architecture Rev 1.10, 5th January 2017, John Croudy The LEO-1 is a complete 16-bit computer system featuring the LEO-1 CPU, a custom-designed CPU. This CPU s architecture was inspired

More information

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide Lecture 9 INC and DEC Arithmetic Operations Overflow Multiply and Divide INC adds one to a single operand DEC decrements one from a single operand INC destination DEC destination where destination can

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

instruction 1 Fri Oct 13 13:05:

instruction 1 Fri Oct 13 13:05: instruction Fri Oct :0:0. Introduction SECTION INSTRUCTION SET This section describes the aressing modes and instruction types.. Aressing Modes The CPU uses eight aressing modes for flexibility in accessing

More information

INSTRUCTION SET AND EXECUTION

INSTRUCTION SET AND EXECUTION SECTION 6 INSTRUCTION SET AND EXECUTION Fetch F1 F2 F3 F3e F4 F5 F6 Decode D1 D2 D3 D3e D4 D5 Execute E1 E2 E3 E3e E4 Instruction Cycle: 1 2 3 4 5 6 7 MOTOROLA INSTRUCTION SET AND EXECUTION 6-1 SECTION

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

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

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

Introduction to Assembly language

Introduction to Assembly language Introduction to Assembly language 1 USING THE AVR MICROPROCESSOR Outline Introduction to Assembly Code The AVR Microprocessor Binary/Hex Numbers Breaking down an example microprocessor program AVR instructions

More information

(2) Explain the addressing mode of OR What do you mean by addressing mode? Explain diff. addressing mode for 8085 with examples.

(2) Explain the addressing mode of OR What do you mean by addressing mode? Explain diff. addressing mode for 8085 with examples. (1) Explain instruction format and Opcode format of 8085 μp with example. OR With help of examples, explain the formation of opcodes of 8085 OR What is an instruction? List type of instruction based on

More information

8085 INSTRUCTION SET INSTRUCTION DETAILS

8085 INSTRUCTION SET INSTRUCTION DETAILS 8085 INSTRUCTION SET INSTRUCTION DETAILS DATA TRANSFER INSTRUCTIONS MOV Rd, Rs Copy from source to destination This instruction copies the contents of the source register Rs into the destination register

More information

EE 308: Microcontrollers

EE 308: Microcontrollers EE 308: Microcontrollers Review Part I Aly El-Osery Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA February 15, 2018 Aly El-Osery (NMT) EE 308:

More information

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017) Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017) High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one

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

ECED 3204 Microprocessor Midterm Reference Solution

ECED 3204 Microprocessor Midterm Reference Solution ECED 3204 Microprocessor Midterm Reference Solution Date: October 26 2017 Time: 7:00pm-9:00pm Room: B225, B227, B229 Student name ID 1) Problem one has following two sub problems: a. Write an instruction

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

Digital Systems - Mini AVR 3

Digital Systems - Mini AVR 3 Digital Systems - Mini AVR 3 Pere Palà - Alexis López itic http://itic.cat April 2016 Enhancing the processor Up to now, we have a linear program flow Suitable for a pre-planned task Unable to react to

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

Chapter 2 SPARC Architecture Chinua Umoja

Chapter 2 SPARC Architecture Chinua Umoja Chapter 2 SPARC Architecture Chinua Umoja 1 SPARC is a load/store architecture Registers used for all arithmetic and logical operations 32 registers available at a time Uses only load and store instructions

More information

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman Microprocessors 1 The 8051 Instruction Set Microprocessors 1 1 Instruction Groups The 8051 has 255 instructions Every 8-bit opcode from 00 to FF is used except for A5. The instructions are grouped into

More information

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier AVR201: Using the AVR Hardware Multiplier Features 8- and 16-bit Implementations Signed and Unsigned Routines Fractional Signed and Unsigned Multiply Executable Example Programs Introduction The megaavr

More information

SN8F5000 Family Instruction Set

SN8F5000 Family Instruction Set SONiX Technology Co., Ltd. 8051-based Microcontroller 1 Overview SN8F5000 is 8051 Flash Type microcontroller supports comprehensive assembly instructions and which are fully compatible with standard 8051.

More information

EC 333 Microprocessor and Interfacing Techniques (3+1)

EC 333 Microprocessor and Interfacing Techniques (3+1) EC 333 Microprocessor and Interfacing Techniques (3+1) Lecture 6 8086/88 Microprocessor Programming (Arithmetic Instructions) Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC

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

Lecture (07) x86 programming 6

Lecture (07) x86 programming 6 Lecture (07) x86 programming 6 By: Dr. Ahmed ElShafee 1 The Flag Register 31 21 20 19 18 17 16 14 13 12 11 10 9 8 7 6 4 2 0 ID VIP VIF AC VM RF NT IOP 1 IOP 0 O D I T S Z A P C 8088/8086 80286 80386 80486

More information

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING Instructions Alphabetical List of Instructions ACALL: Absolute Call ADD, ADDC: Add Accumulator (With Carry) AJMP: Absolute Jump ANL: Bitwise AND CJNE: Compare

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

Arithmetic and Logic Instructions And Programs

Arithmetic and Logic Instructions And Programs Dec Hex Bin 3 3 00000011 ORG ; FOUR Arithmetic and Logic Instructions And Programs OBJECTIVES this chapter enables the student to: Demonstrate how 8-bit and 16-bit unsigned numbers are added in the x86.

More information

Arithmetic Instructions

Arithmetic Instructions Segment 3C Arithmetic Instructions This topic covers the following instructions: Addition (ADD, INC, ADC) Subtraction (SUB, DEC, SBB,CMP) Multiplication (MUL, IMUL) Division (DIV, IDIV) BCD Arithmetic

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

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

Instructions moving data

Instructions moving data do not affect flags. Instructions moving data mov register/mem, register/mem/number (move data) The difference between the value and the address of a variable mov al,sum; value 56h al mov ebx,offset Sum;

More information

COMP3221: Microprocessors and Embedded Systems

COMP3221: Microprocessors and Embedded Systems Embedded Systems Lecture 6: Addressing Modes http://www.cse.unsw.edu.au/~cs3221 Lecturer: Hui Wu Session 2, 2005 Addressing Modes Overview Instruction Examples 1 2 Operands Immediate Addressing Instructions

More information

TUTORIAL Assembly Language programming (2)

TUTORIAL Assembly Language programming (2) 8051 Assembly Language programming (2) TUTORIAL 4 EEE3410 Microcontroller Applications 1. Write the instructions to move value 34h into register A and value 3Fh into register B, then add them together.

More information

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Q. Classify the instruction set of 8051 and list out the instructions in each type. INTRODUCTION Here is a list of the operands and their meanings: A - accumulator; Rn - is one of working registers (R0-R7) in the currently active RAM memory bank; Direct - is any 8-bit address register

More information

Instruction Set Instruction set of 8085 can be classified in following groups: Data Transfer Instructions These instructions can perform data transfer operations between Registers of 8085 e.g. MOV 8085

More information

DR bit RISC Microcontroller. Instructions set details ver 3.10

DR bit RISC Microcontroller. Instructions set details ver 3.10 DR80390 8-bit RISC Microcontroller Instructions set details ver 3.10 DR80390 Instructions set details - 2 - Contents 1. Overview 7 1.1. Document structure. 7 2. Instructions set brief 7 2.1. Instruction

More information

Microprocessors & Interfacing

Microprocessors & Interfacing Lecture Overview Microprocessors & Interfacing AVR Programming (II) Lecturer : Dr. Annie Guo Assembly program structure Assembler directives Assembler expressions Macros Memory access Assembly process

More information

TYPES OF INTERRUPTS: -

TYPES OF INTERRUPTS: - There are 3 types of interrupts. TYPES OF INTERRUPTS: - External Interrupts. Internal Interrupts. Software interrupts. Hardware Interrupts (1) External interrupts come from I/O devices, from a timing device

More information

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C ARITHMETIC AND LOGICAL GROUPS 6-1 Arithmetic and logical groups: The arithmetic group includes instructions for the addition, subtraction, multiplication, and division operations. The state that results

More information

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

ET355 Microprocessors Thursday 6:00 pm 10:20 pm ITT Technical Institute ET355 Microprocessors Thursday 6:00 pm 10:20 pm Unit 4 Chapter 6, pp. 139-174 Chapter 7, pp. 181-188 Unit 4 Objectives Lecture: BCD Programming Examples of the 805x Microprocessor

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

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

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