30-Sep-0194.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 20011 Problem: must convert ideas (human thoughts) into an executing.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

The Assembly Language Level
8086 Assembly Language Programming I
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
The 8086 Assembly Programming Data Allocation & Addressing Modes
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
8051 ASSEMBLY LANGUAGE PROGRAMMING
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Chapter 2 Software Tools and Assembly Language Syntax.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
CPS120: Introduction to Computer Science
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
CoE3DJ4 Digital Systems Design
ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Faculty of Engineering, Electrical Department,
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
Chapter Five–80x86 Assembly program development Principles of Microcomputers 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 1.
4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  direct mode: OK for static addresses  indirect register mode:
SYSC 2001*: copyright ©T. Pearce, D. Hutchinson, L. Marshall Nov Virgo lectures- revised Nov. 14, Virgo Ch. 11 of Stallings has been incorporated.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Assembly Language programming
Review of Assembly language. Recalling main concepts.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Assembly Lab 3.
Assembly Language programming
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
System Programming and administration
The 8051 Microcontroller and Embedded Systems
Additional Assembly Programming Concepts
Assembler Directives Code generation flow
Microprocessor Systems Design I
Microprocessor and Assembly Language
Chapter 4 Addressing modes
Microprocessor and Assembly Language
Processor Processor characterized by register set (state variables)
Assembly Lang. – Intel 8086 Addressing modes – 1
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
Symbolic Instruction and Addressing
A Simple Two-Pass Assembler
INTRODUCTION ABOUT ASSEMBLY
8051 ASSEMBLY LANGUAGE PROGRAMMING
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
Computer Organization and Assembly Language
Introduction to 8086 Assembly Language
Presentation transcript:

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Problem: must convert ideas (human thoughts) into an executing program (binary image in memory) Need: DEVELOPMENT PROCESS  people-friendly way to write programs  tools to support conversion to binary image  assembly language: used by people to describe programs syntax: set of symbols + grammar rules for constructing statements using symbols semantics: what is meant by statements; ultimately: the binary image Assembly Language / Development Process

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept assembler: program – converts programs from assembly language to object format object format: an intermediate format –mostly binary, but may include other info linker: program that combines object files to create an “executable” file loader: loads executable files into memory, and may initialize some registers (e.g. IP ) Assembler, linker and loader are tools. Assembly Language / Development Process

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Development Process.EXE Linker loader is part of operating system (or possibly debugger) simulator loads.OBJ files directly Computer System Loader memory processor IP.OBJ.ASM.OBJ.LST Assembler human readable results (including assembly errors) may link multiple OBJ files Editor people work here

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  people create.ASM files using assembly language  syntax must account for all aspects of a program and development process: constant values reserve memory to use for variables write instructions: operations & operands –addressing modes directives to tools in development process p86 Assembly Language

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept binary value: consists of only 0’s and 1’s  ends with ‘B’ or ‘b’, e.g b hexadecimal value: starts with  may include 0.. 9, A.. F (a.. f )  ends with ‘H’ or ‘h’, e.g. 0FFH (8-bit hex value) decimal value: default format – no “qualifier” extension  consists of digits in 0.. 9, e.g string: sequence of characters encoded as 7-bit ASCII bytes:  enclosed in single quotes, e.g. ‘Hi Mom’ (6 bytes)  character: string with length = 1 p86 Assembly Language: Constants

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  user-defined names – represent addresses  lets programmer refer to addresses using logical names – no need for concern with exact hexadecimal values  leave assembler to: decide exact addresses to use deal with hexadecimal addresses  labels are used to identify addresses for: control flow – identify address of target memory variables – identify address where data is stored  labels serve in 2 roles: label definition and label reference p86 Assembly Language: Labels

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  used by assembler to decide exact address  must be first non-blank text on a line  user-defined name followed by “:”  name must start with alpha A.. Z a.. z  then contain: alpha, numeric, ‘_’ e.g. Continue: L8R: Out_2_Lunch:  cannot redefine reserved words e.g. MOV: is illegal p86 Assembly Language: Label Definition

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  label represents address of first allocated byte after definition e.g. DoThis:MOVAX, [ BX ] DoThis represents address of first byte of the MOV instruction  label reference: use of label in an operand refers to address assigned by assembler (no “:”)  control flow example (assume CX contains loop counter): DoWhile: CMP CX, 0 JEDoneDoWhile … JMPDoWhile DoneDoWhile: MOVAX,... (etc.) p86 Assembly Language: Label Address/Reference

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  reserve memory for variables  2 sizes: DBreserves a byte of memory DWreserves a word (2 bytes) of memory  may also provide an (optional) initialization value as an operand Examples: DB; reserves one byte X:DB; reserves one byte – label X is ; defined to represent the address ; of the byte Y:DB3; reserve one byte – label Y etc. ; and initialize the byte to 3 p86 Assembly Language: Memory Declarations

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Examples (continued): DW; reserve 2 consecutive bytes Z:DW; reserves 2 bytes – label Z is defined to represent the ; address of the first byte W:DW 256; reserve 2 bytes – label W etc., and initialize the bytes ; to 256 decimal (little endian !!!) HUH:DW W ; reserve 2 bytes – label HUH etc., and initialize the ; bytes to contain the address of the variable W above A: B: DB ‘C’; reserves 1 byte – labels A and B both represent the : address of the byte, and initializes it to 43H p86 Assembly Language: Memory Declarations

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  complete instruction must be on one line  instruction mnemonic & operands  operands immediate: constant –can use label reference, example: W:DW... MOVBX, W register:register name direct:[ address ] –state address a label reference, example: W:DW... MOVAX, [ W ] p86 Assembly Language: Instructions

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  Operands (continued) register indirect: [ register ] –example W:DW... MOVBX, W MOVAX, [ BX ] relative-offset(control flow) –use label reference to identify target address –assembler calculates actual offset JMPThere... There: etc. p86 Assembly Language: Instructions

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  statements that are intended to help tools  are not assembled directly into instructions or memory declarations END Directive:  directive to 2 tools: assembler and loader  directs assembler to stop reading from.ASM file any subsequent statements are ignored  operand: must be a label reference interpreted as specifying the address of the first instruction to be executed directs loader to load specified address into IP after loading.OBJ file Syntax: ENDlabel-reference p86 Assembly Language: Tool Directives

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  each pass: processes all statements in.ASM file sequentially from start to finish 1 st Pass: for each statement: 1.check syntax 2.allocate any memory needed for image –memory declaration (DB, DW) –instruction: opcode + operands 3.if includes a label definition: assign value to label and keep record of (label, value) association in Symbol Table  if syntax errors in 1 st pass, then write errors to.LST file and stop, else nd Pass: build binary for each statement: may require calculating offsets – may result in errors – e.g. trying to jump too far for a conditional jump (target out of range) write results to.LST file if no errors – write results to.OBJ file p86 Assembly Language: 2 Pass Assembly Process

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Memory Allocation:  assumes allocation starts at address 0000H  uses location counter ($) to track address of next byte to allocate  as bytes are allocated, adjust $ value  for each memory declaration: (DB, DW) allocate # bytes declared, for example: suppose $ = 0006H and next line of program is: DW –will allocate 2 bytes for DW statement: »use address 0006H for low byte »use address 0007H for high byte –after allocation: $ = 0008H (next byte to allocate) if next line of program is: DB ‘Hi Mom’ –will allocate 6 bytes for DB statement »use address 0008H for ‘H’, …, 000DH for ‘m’ –after allocation: $ = 000EH p86 Assembly Language: 1 st Pass in Detail

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  for each instruction: allocate bytes needed to encode opcode and operands example: suppose $ = 0006H when next line of program is: MOV CL, BL –requires 2 bytes to encode instruction: opcode, CL dest, BL source –after allocation: $ = 0008H if next line of program is: MOVBX, 1 –requires 4 bytes to encode –2 bytes: opcode, BX dest, imm as src –2 bytes: imm src value –after allocation: $ = 000CH  when a label definition is encountered: value of label = $ –value of label is the address of the next byte allocated to the program save (label, $-value) in Symbol Table for recall during 2 nd pass p86 Assembly Language: 1 st Pass in Detail Instruction encoding details later

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  build image of bytes to be loaded at addresses  memory declaration: initialization value? if no init value – use default?  instructions: opcodes and operands addressing mode info label references in operands: look up values to use for label in Symbol Table for relative-offsets: offset = label-value – $  results to.LST file errors image created (none if errors!) .OBJ file contains image in format that can be loaded by simulator includes info about “start address” – to initialize IP during loading p86 Assembly Language: 2 nd Pass in Detail

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept $binary image 0000 start: 0000 C7C2E904 mov dx, 04E9H 0004 C6C048 mov al, 'H' 0007 EE out [dx], al 0008 C6C069 mov al, 'i' 000B EE out [dx], al 000C F4 hlt end start After 1 st Pass:  syntax OK  bytes have been allocated to statements  Symbol Table constructed: SymbolValue start0000H After 2 nd Pass:  binary image constructed p86 Assembly Language: HI.LST Example Label definition: in 1 st pass – put value in Symbol table

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Start: C7C4FEFF mov sp, 0FFFEH C7C2E904 mov dx, 04E9H C6C510 mov ch, B C6C101 mov cl, E 8B1EA300 mov bx, [Value] Outloop: D3E3 shl bx, cl jc Got Got0: C6C030 mov al, ‘0’ E90300 jmp Dump C Got1: 55001C C6C031 mov al, ‘1’ F Dump: F EE out [dx], al p86 Assembly Language: ASSIGN2.LST Example

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept ED01 sub ch, ED jnz Outloop SymbolValue Start0000H Outloop0012H Got00016H Got1001CH Dump001FH B 0A00 Ten: dw D 6400 Hundred: dw F E803 Thousand: dw A TenThousand: dw A3 AF90 Value: dw 090AFH SymbolValue Ten009BH Hundred009DH Thousand009FH TenThousand00A1H Value00A3H p86 Assembly Language: ASSIGN2.LST Example Note: Do not confuse $ with IP $ = artifact of assembler IP = artifact of processor

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  allows declaration of symbolic constants  improves (human) readability  reduces the use of “magic numbers” Syntax: symbolic-name EQU numeric-constant  1 st Pass: records (symbolic-name, constant) in symbol table  2 nd Pass: replaces every occurrence of the symbolic-name with the specified constant is NOT allocated any bytes !!! p86 Assembly Language: EQU Directive Note: No “:”

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept DisplayPort EQU04E9H ; magic number MOVDX, DisplayPort ; improved readability  is assembled to same encoding as MOVDX, 04E9H p86 Assembly Language: EQU Example

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  allows specification of the address of the next byte to be allocated  improves (human) readability  reduces the use of “magic numbers” Syntax: ORG numeric-constant  Assembler assigns location counter the value of the specified numeric constant p86 Assembly Language: ORG Directive

30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept … JMPDoAtF000H ; suppose this instruction was ; assembled to bytes starting at 0120H ORG 0F000H DoAtF000H: MOVBX,... ; MOV instruction will be assembled ; to bytes starting at address F000H  Must always increase location counter (never decrease)  Typical use: Force assembly to specific address range Resulting code will reside in particular type of memory located at that address (e.g. ROM) p86 Assembly Language: ORG Example