Machine Language and Assembly Language

Slides:



Advertisements
Similar presentations
Stack Memory 00000H 00001H 01058H TOS SS SP 1104FH BOS
Advertisements

Intel 8086.
Processor Data Path and Control Diana Palsetia UPenn
Computer Science Education
SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
Embedded Software 1. General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator)
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Chapter 4 The Von Neumann Model
Chapter 4 The Von Neumann Model
Execution Cycle. Outline (Brief) Review of MIPS Microarchitecture Execution Cycle Pipelining Big vs. Little Endian-ness CPU Execution Time 1 IF ID EX.
CS/COE1541: Introduction to Computer Architecture Datapath and Control Review Sangyeun Cho Computer Science Department University of Pittsburgh.
Registers of the 8086/ /2002 JNM.
©UCB CPSC 161 Lecture 3 Prof. L.N. Bhuyan
ARM versions ARM architecture has been extended over several versions.
Lab 4 Design a processor to implement the Fibonacci sequence
CSC 3210 Computer Organization and Programming
Appendix D The ARM Processor
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620.
Overheads for Computers as Components 2nd ed.
Introduction to Computer Systems
Suranaree University Of Technology มทส  2002 Anant Oonsivilai 2002/2/27 Microcomputers and Microprocessors Chapter Assembly Language Programming.
Chapter 3 โพรเซสเซอร์และการทำงาน The Processing Unit
CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems.
KU College of Engineering Elec 204: Digital Systems Design
Class Addressing modes
MIPS Assembly Tutorial
THUMB Instructions: Branching and Data Processing
Multiplication – Microprocessor
Instruction Set Design
Assembly Language Programming
INSTRUCTION SET ARCHITECTURES
Address Indirect Addressing with Index and Displacement – Mode 6 Opcode - 4dRn - 3dmd - 3sMS - 6 rt - 1xm - 3s -1und - 3 displacement - 8 rt – type of.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Memory Locatıons and Addresses (Week 3)
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
9/20/6Lecture 3 - Instruction Set - Al Instruction Set.
Microprocessor Fundamentals Week 5 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Execution of an instruction
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Pentium Addressing Modes
1 Instructions and Addressing
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Computer Architecture and the Fetch-Execute Cycle
9/20/6Lecture 3 - Instruction Set - Al Instruction Set (2)
CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Execution of an instruction
Computer Architecture Lecture 03 Fasih ur Rehman.
In1210/01-PDS 1 TU-Delft Instructions and addressing.
Computer Organization 1 Instruction Fetch and Execute.
Computer Organization Instructions Language of The Computer (MIPS) 2.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
1 Instructions and Addressing Course website:
Addressing Modes in Microprocessors
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
ECE 3430 – Intro to Microcomputer Systems
A Closer Look at Instruction Set Architectures: Expanding Opcodes
Computer Science 210 Computer Organization
Lecture 3 - Instruction Set - Al
The Processor and Machine Language
Computer Science 210 Computer Organization
Computer Organization and ASSEMBLY LANGUAGE
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
Topic 6 LC-3.
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Introduction to Micro Controllers & Embedded System Design
MARIE: An Introduction to a Simple Computer
Open Education Resource-OER on Microprocessor 8085 Instruction Set By Dr. S. N. Sampat, Team leader Ms. R. P. Merchant, Member Mr. A. K. Bilakhia, Member.
Presentation transcript:

Machine Language and Assembly Language In the following lectures, we will learn: How instructions are represented and decoded Introduction to different types of Addressing Modes Most commonly used assembly instructions Writing simple assembly language programs Hand assembly – process of converting assembly language program to machine language Other assembly instructions such as Logical instructions

Instruction Format Reminder: Instruction Interpreter interprets the type of operation, nature of operands (data or address), and mode (memory or register). Overall it interprets the mode of addressing. General format of instruction encoding is: OP: opcode (4 bits) dRn: 3 bits of destination register Om: 3 bits of operation mode or opcode sMS: 6 bits for source Mode Specification:  3 bits for mode and 3 bits for register used Example: Instruction suba a0,a0 encodes into 90C8 in Hex Here opcode is 1001, which stands for a subtraction 000 stands for destination register used is 0 011 indicates destination register used is an address register with word length 001 000 indicates source mode is 001 (mode 1), and source register used is a0. OP (4) dRn (3) om (3) sMS (6) 1001 000 011 001 000

Instruction Format Another Example: Instruction muls d1,d2 encodes into C5C1 in Hex Here opcode is 1100, which stands for a multiplication 010 stands for destination register used is d2 111 indicates destination register used is always data register 000 001 indicates source mode is 000 (mode 0), and source register used is d1. By Default: instruction operations are on least significant word, therefore the two data are FFFD and 0006. The result of multiplication of two word length data is a longword, the data (-3) is sign-extended to $FFFF FFFD in a working register, before being multiplied by $0006. d1 (source reg) remains unchanged d2 (destination reg) changes to the result value 1100 010 111 000 001 d1 F348 FFFD = -3 d2 0000 0006 x 6 FFFF FFEE - 18 FFFF FFFD = -3 x 0006 x 6 d2 FFFF FFEE - 18

Instruction Format Another Multiplication Example: muls d3,d0 d3 is source register, and d0 is destination register By Default: instruction operations are on least significant word, therefore the two data are $0073 and $0295. The result of multiplication of two word length data is a longword. Both the data are positive, so no need to sign-extended d3 (source reg) remains unchanged d0 (destination reg) changes to the result value d3 D3AB 0073 = 115 d0 F348 0295 x 661 0001 28EF 76015

Effective Address Recall, the address bus for Motorola 68K is 24 bits. Therefore, the memory addresses are 24 bits long. Let the destination be a memory location, and the source be a data register. The instruction in machine language would look something like below: If addresses are explicitly defined as part of the machine language, the instruction becomes too long (2 words instead of 1 word), and accessing the instruction would require more memory accesses. Therefore, Effective Address (EA), which is the address of memory location to be accessed, is not specified in the instruction. Instead, an address register (requires 3 bits to be specified), which contains the EA is used. In other words, address register points to the memory location used. Example: if memory location $0ABCD6 needs to be accessed, then an address register, say a0, should contain $000ABCD6 Now, if we want to access memory location $0ABCD8, we just need to add 2 to a0, and it will point to this new location 5-bit opcode 24-bit memory address 3-bit data register

Instruction: using Effective Address Example: move instruction From Register to Memory location – Mode 2 move d2, (a0) ( ) brackets specify the operand is a memory location Here, EA = [a0], the contents of a0 Suppose a0 = $000ABCD6 (32-bit register) and d2 = $12345678 (32-bit register) The above instruction specifies that the least significant word (lsw) of d2, that is $5678, is moved (copied) to the memory address specified by a0 8 bits 000000 000001 000002 0ABCD6 0ABCD7 Opcode dRn (3) dmd (3) sMS (6) 0011 000 010 000 010 $56 $78

Another Example: move instruction with displacement Mode 5 From Memory location to Register move displ(aj), di move $4(a0), d3 Equivalent Machine instruction is therefore Here, EA = [a0] + sign-ext displacement sign-extend displacement to 32-bits Add to the 32-bit contents of a0 The low-order 24 bits represent the EA Suppose a0 = $0000 0008 (32-bit register) Sign-extended displacement = $0000 0004 Then Effective Address = $0000 000C (consider lower 24-bits) Assume initially d3 = $12345678 (32-bit register) The above instruction moves (copies) the contents of the memory address specified by EA to register d3. After move, d3 = $1234ABCD 8 bits 000000 000001 000002 00000C 00000D opcode dRn dmd sMS S-displ (16-bit) 0011 011 000 101 000 0000 0000 0000 0100 3628 0004 $AB $CD

Negative displacement Example Since displacement can be negative as represented in 2’s complement form move d3, $FFFC(a0) If a0 = 0000 0008 EA = 0000 0008 (a0) + FFFF FFFC (sign-extended displ) 0000 0004 Therefore, according to the instruction, low-order word of d3 moves to memory location $000004 a0 and d3 remain unchanged.

Memory-to-memory instruction move displ(ai), displ(aj) Here both source and destination have Mode 5. move 164(a0), 6(a1) M[a1 + 6]  M[a0 + $A4] 0011 dAn 101 101 sAn s-displ d-displ 0011 001 101 000 $00A4 $0006

Addressing Modes The addressing modes that we have seen until now are: Mode 0: Data Register Direct addressing Example: move d0, d1 Data size may be byte, word, or longword Mode 1: Address Register Direct Addressing Example: move a0, a1 Because address register specified, valid sizes are word, or longword Mode 2: Address Register Indirect Addressing Example: move d0, (a1) Mode 5: Address Register Indirect Addressing with Displacement Example: move d0, $A(a1) Displacement size is always a word and sign-extended

Micro-instructions for move d3, 2(a0) MAR  PC 3143 0002 PC MBR  M[MAR] IR  MBR PC  PC + 2 PC points to displacement Decode MBR  M[MAR] Displacement loaded MAR  A0 + MBR Effective Address calculated MBR  D3 Source data moved to memory location given by Effective Address [MAR]  MBR PC  PC + 2 PC points to next instr. now

Simple Assembly Language program We want to add two 16-bit numbers in memory locations provided consecutively (that is locations X and X+2). Save the result in X+4. We need to first move the data in location X to a data register, say d1 The instruction is therefore of the format move displ(aj), di Now, for us the EA = X Therefore, displ + aj = X  If displ = X, then aj = 0 Therefore, our instruction will be move X(a0), d0 with a0 initialized to 0. movea.l #$0, a0 ; a0 initialized to 0, a0 = 0000 0000 move X(a0), d0 ; d0 = ???? 0004 move X+2(a0), d1 ; d1 = ???? 0106 add d1, d0 ; d0 = ????010A move d0, X+4(a0) 0004 X 0106 X+2 ???? X+4

Example for Mode 5 (with displacement) Offset (displacement) as a constant Offset (displacement in the address register a1 Register a1 is used as the reference point 0000 1000 a1 The sub-program can be better written as 0000 0020 Add $20(a1),d2 Add $22(a1),d2 Add $24(a1),d2 …… 1000 …….. 1020 1022 1024 ….. Add $1000(a1),d2 Add #2, a1 ….. 1000 1020 1024 N n …. Num1 First Number Second Number ….. Nth Number LOOP Add (a0), d0 Add #2, a0 Sub #1, d1 BGT LOOP d1 n a0 Num1

Another Example for Mode 5 Figure 2.14 from Hamacher book Figure 2.15 from Hamacher textbook Example of using both, Offset as a Constant and Offset in the register N n LIST Student ID LIST + 4 Test 1 LIST + 8 Test 2 LIST + 12 Test 3 LIST + 16 …... ….. Move #LIST, R0 Clear R1 Clear R2 Clear R3 Move N, R4 LOOP Add 4(R0), R1 Add 8(R0), R1 Add 12(R0), R1 Add #16, R0 Decrement R4 Branch>0 LOOP Move R1, SUM1 Move R2, SUM2 Move R3, SUM3 Student 1 Test1 Test2 Test3 Student 2 Test1 Test2 Test3 ….. Student n Test1 Test2 Test3 SUM1 SUM2 SUM3 Offset as a constant Offset in a register