CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

The Assembly Language Level
Chapter 3 Loaders and Linkers
Machine Independent Assembler Features
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
Machine-Dependent Assembler Features (SIC/XE Assembler) Instruction Formats, Addressing Modes, and Program Relocation.
System Software by Leland L. Beck chapter 1, pp.1-20.
System Software.
Assembler design.
Chapter 6: Machine dependent Assembler Features
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
Chih-Hung Wang Chapter 2: Assembler (Full) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Chapter 2 Assemblers Assembler Linker Source Program Object Code
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Assembler – Machine Dependent Features
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
An introduction to systems programming
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming November 30, 2006.
Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Assembler (Basic Functions)
UNIT II ASSEMBLERS.
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
CSC 221 Computer Organization and Assembly Language
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Assemblers.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
ECE291 Computer Engineering II Lecture 3 Josh Potts University of Illinois at Urbana- Champaign.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
ECE291 Computer Engineering II Lecture 3 Josh Potts University of Illinois at Urbana- Champaign.
G.Umamaheswari Lect/IT R.M.D.EC system software
ECE291 Computer Engineering II Lecture 3 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
8086/8088 Instruction Set, Machine Codes and Addressing Modes.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Data Movement Instructions A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
CC410: System Programming
Machine dependent Assembler Features
Credits and Disclaimers
Format of Assembly language
Assembly Lab 3.
CC410: System Programming
System Programming and administration
System Programming and administration
16.317: Microprocessor System Design I
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Microprocessor Systems Design I
THE sic mACHINE CSCI/CMPE 3334 David Egle.
BIC 10503: COMPUTER ARCHITECTURE
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Loaders and Linkers.
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 6 Programming the basic computer
Machine Independent Assembler Features
An introduction to systems programming
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Presentation transcript:

CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1

2 Learning Objectives Understand Assemblers functions Differentiate machine dependant vs machine independent features

Assembler Definition: An Assembler is a Program that has the following tasks: 1. Transform assembly instructions (source code, such as MOV) into machine code (binary, such as ) 2. Assign memory addresses to symbolic labels 3. Create an object code file 3 Source Program Assembler Object Code Loader Executable Code Linker

4 2.1 Basic Assembler Functions »Figure 2.1 shows an assembler language program for SIC. –The line numbers are for reference only. –Indexing addressing is indicated by adding the modifier “X” –Lines beginning with “.” contain comments only. –Reads records from input device (code F1) –Copies them to output device (code 05) –At the end of the file, writes EOF on the output device, then RSUB to the operating system

5

6

7

8 2.1 Basic Assembler Functions »Assembler directives (pseudo-instructions) –START, END, BYTE, WORD, RESB, RESW. –These statements are not translated into machine instructions. –Instead, they provide instructions to the assembler itself.

9 2.1 Basic Assembler Functions »Data transfer (RD, WD) –A buffer is used to store record –Buffering is necessary for different I/O rates –The end of each record is marked with a null character (00 16 ) –Buffer length is 4096 Bytes –The end of the file is indicated by a zero- length record »Subroutines (JSUB, RSUB) –RDREC, WRREC –Save link (L) register first before nested jump

A simple SIC Assembler »Figure 2.2 shows the generated object code for each statement. –Loc gives the machine address in Hex. –Assume the program starting at address »Translation functions –Translate STL to 14. –Translate RETADR to –Build the machine instructions in the proper format (,X). –Translate EOF to 454F46. –Write the object program and assembly listing.

11

12

13

A simple SIC Assembler »A forward reference –101000FIRST STLRETADR –A reference to a label (RETADR) that is defined later in the program –Most assemblers make two passes over the source program »Most assemblers make two passes over source program. –Pass 1 scans the source for label definitions and assigns address (Loc). –Pass 2 performs most of the actual translation.

A simple SIC Assembler »The object program (OP) will be loaded into memory for execution. »Three types of records –Header: program name, starting address, length. –Text: starting address, length, object code. –End: address of first executable instruction.

A simple SIC Assembler

A simple SIC Assembler »The symbol ^ is used to separate fields. –Figure 2.3 1E(H)=30(D)=16(D)+14(D)

A simple SIC Assembler »Assembler’s Functions –Convert mnemonic operation codes to their machine language equivalents STL to 14 –Convert symbolic operands (referred label) to their equivalent machine addresses RETADR to 1033 –Build the machine instructions in the proper format –Convert the data constants to internal machine representations –Write the object program and the assembly listing

A simple SIC Assembler »Example of Instruction Assemble –Forward reference –STCH BUFFER, X (54) 16 1 (001) 2 (039)

A simple SIC Assembler »Forward reference –Reference to a label that is defined later in the program. LocLabelOP CodeOperand 1000FIRSTSTLRETADR 1003CLOOPJSUBRDREC … ……… 1012JCLOOP … ……… 1033RETADRRESW1

A simple SIC Assembler »The functions of the two passes assembler. »Pass 1 (define symbol) –Assign addresses to all statements (generate LOC). –Save the values (address) assigned to all labels for Pass 2. –Perform some processing of assembler directives. »Pass 2 –Assemble instructions. –Generate data values defined by BYTE, WORD. –Perform processing of assembler directives not done during Pass 1. –Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).

Intel Architecture Assembler Example

1 st Table: Symbol Table Symbol table: List of “items” in this file that may be used by this and other files. What are they? –Labels: function calling –Data: anything in the.data section; variables which may be accessed across files First Pass: record label-address pairs Second Pass: produce machine code –Result: can jump to a label later in code without first declaring it

Generating Machine Code for an Instruction Op-codeMod-Reg-R/MDisplacementimmediate This is complex due to the large variety of addressing modes combined with the large number of instructions. Most often, the machine code for an instruction consists of 1) an 8-bit opcode (the choice of opcode will depend somewhat on the addressing modes used for the operands) followed by 2) one or more bytes describing the addressing modes for the operands. Instruction format of the pentium 4 microprocessor 1-2 bytes0-1 bytes0-4 bytes

1- MOD-REG-R/M byte  Mod Field: addressing mode = 00, 01, 10 the R/M (register/Memory) selects one of the data memory addressing modes 00 no displacement, read from first operand from REG and second operand from R/M 01 8-bit displacement bit displacement = 11 it selects the register addressing mode, Register addressing uses R/M field to specify a register instead of memory location MODREGR/M

REG and R/M Field (when MOD=11) CodeW=0 (byte)W=1 (word)W=1 (double word) 000ALAXEAX 001CLCXECX 010DLDXEDX 011BLBXEBX 100AHSPESP 101CHBPEBP 110DHSIESI 111BHDIEDI

R/M Field (16-bit addressing mode) codefunction 000[BX+SI] 001[BX+DI] 010[BP+SI] 011[BP+DI] 100[SI] 101[DI] 110[BP]/DISP16 111[BX]

R/M Field (32-bit addressing mode) codefunction 000[EAX] 001[ECX] 010[EDX] 011[EBX] 100Displacement 101[EBP] 110[ESI] 111[EDI]

1- op-code Byte DW  If D=1 then data transferred to the REG field from the R/M field (second operand)  If D=0 then data transferred to the R/M field from the REG field (first operand) - W=1 if data size is a word or double word -W=0 if data size is a byte

MODREGR/M Example MOV DL, [DI] D1D1 W0W0 D =1 from memory to register W=0 DATA SIZE IS BYTE MODE=No displacement = then the hexadecimal code is (machine code) : 8A15

MODREGR/M Example MOV BP, SP D1D1 W1W1 MODE= register addressing mode= 11 D =1 from “memory field” to “register field” W=1 DATA SIZE IS WORD then the hexadecimal code is (machine code) : 8BEC