Download presentation
Presentation is loading. Please wait.
Published byNancy Goodwin Modified over 8 years ago
2
1 Computer Architecture & Assembly Language Spring 2001 Dr. Richard Spillman Lecture 10 –Assembly V
3
2 Semester Topics PLU 1 Assembly Language CPU Disk Memory I/O ALU Assembly Microprogramming Alternatives Cache Virtual Structure Operation Network
4
3 Review – Last Lecture More on DOS Calls BIOS Calls Conditional Statements
5
4 Outline Macros Additional Instructions Running a Program Intro to Pentium Systems It’s too much my circuits hurt
6
5 Macros A macro is a set of assembly language statements given a symbolic name. After being defined, the assembler will substitute those statements whenever it finds the symbolic name. MASM = Macro Assembler
7
6 Example Define macros to input and print a character ; Input a character into al mInputChar macro mov ah, 1 int 21h endm ; print character in dl mPutChar macro mov ah, 2 int 21h endm
8
7 Macro Assembly Then writing mInputChar mov dl, al mPutChar results in the code mov ah, 1 int 21h mov dl, al mov ah, 2 int 21h Observe the text substitution
9
8 Macro Parameters Macros can have parameters. The text for the actual parameter is substituted for the name of the dummy parameter when the macro is invoked. §mInputChar macro aChar push ax mov ah, 1 int 21h mov aChar, al pop ax endm
10
9 Example mInputChar bl mInputChar aCh expands to push ax mov ah, 1 int 21h mov bl, al pop ax push ax mov ah, 1 int 21h mov aCh, al pop ax
11
10 Macros vs Procedures Similarities: Both Simplify program writing Encourage reuse of code Improve program readability Provide better structure to programs
12
11 Differences Macro 1. Can be used for any kind of code even data decl. Procedure 1. Can only be used for executable code. 5. Use does not change execution speed 5. Use decreases execution speed 4. No extra instructions 4. Needs CALL and RET 3. Use or non-use does not change code length 3. Longer procedures shorten code if used repeatedly 2. Expanded code appears in.EXE each time used 2. Generated code only appears once in.EXE
13
12 Additional Instructions There are over 100 instructions in the Intel assembly language and we have only consider a few of them Some will be introduced as we study additional architectural issues Some will not be covered and are left to you to research Some will be covered in this lecture
14
13 XCHG The XCHG instruction swaps (exchanges) the contents of the two operands. This instruction takes the place of THREE MOV instructions. The XCHG instruction can swap Two byte operands. Two word operands. Two doubleword operands. The operands may be Two register operands. One memory operand and one register operand. Note: XCHG can NOT be used to swap The contents of two segment registers. The contents of two memory locations. xchg AX,BX
15
14 LODSB The LODSB instruction loads a byte from memory into the AL register and increments or decrements SI by one. The source operand is a byte stored in memory at address DS:SI The increment/decrement is determined by the D flag
16
15 STOSB The STOSB instruction stores AL in memory in the extra segment at the offset given by DI and increments DI by one. The destination operand is memory address ES:SI
17
16 XLAT XLAT stands for Table Lookup and Translation. This instruction is useful when you have a table of byte codes stored in memory { like seven-segment LED codes} Before the XLAT instruction, you put the index of the code you want into the AL register and the offset address of the table into the BX register. The XLAT instruction reads the desired byte code out of the table and puts it into the AL register.
18
17 Example GOAL: store the ASCII code for the 16 hex digits in a table so that the code can be accessed using the hex digit as an index Store the table table db ‘0123456789ABCDEF’ Set up registers BX and AL Use XLAT instruction
19
18 Example (continued) Memory looks like: 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 Find the ASCII code for “A” MOV AL, 0Ah :set AL with the index MOV BX, offset table :BX points to beginning BX XLAT :Lookup the value AL Load AL with 41
20
19 Running a Program Running a program involves several steps: C++ Compiler Assembly Program Assembler Object Code (Machine Language) Linker Library Executable Code (Machine Language) Loader Memory
21
20 Assembler Reads and Uses Directives Directives give instructions to the assembler but do not produce machine language instructions.data,... Produce Machine Language Creates Object File
22
21 Object File Format object file header: size and position of the other pieces of the object file text segment: the machine code data segment: binary representation of the data in the source file relocation information: identifies lines of code that need to be “handled” symbol table: list of this file’s labels and data that can be referenced debugging information
23
22 Link Editor/Linker Combines several object (.o) files into a single executable (“linking”) Enable Separate Compilation of files Changes to one file do not require recompilation of whole program Windows NT source is >30 M lines of code! And Growing! Called a module Link Editor name from editing the “links” in jump and link instructions
24
23 Linker Tasks Step 1: Take text segment from each.o file and put them together. Step 2: Take data segment from each.o file, put them together, and concatenate this onto end of text segments. Step 3: Resolve References Go through Relocation Table and handle each entry That is, fill in all absolute addresses
25
24 Loader Executable files are stored on disk. When one is run, loader’s job is to load it into memory and start it running. In reality, loader is the operating system (OS) loading is one of the OS tasks
26
25 Loader Tasks I Reads executable file’s header to determine size of text and data segments Creates new address space for program large enough to hold text and data segments, along with a stack segment Copies instructions and data from executable file into the new address space (this may be anywhere in memory)
27
26 Loader Tasks II Copies arguments passed to the program onto the stack Initializes machine registers Most registers cleared, but stack pointer assigned address of 1st free stack location Jumps to start-up routine that copies program’s arguments from stack to registers and sets the PC If main routine returns, start-up routine terminates program with the exit system call
28
27 Running Summary Compiler converts a single HLL file into a single assembly language file. Assembler converts what it can to machine language and creates a checklist for the linker (relocation table). This changes each.s file into a.o file. Linker combines several.o files and resolves absolute addresses. Loader loads executable into memory and begins execution
29
28 Introduction to Pentium Systems The Pentium Pro system is a far cry from the 8086 architecture System busL2 cache Bus Interface Unit L1 instruction cacheL1 data cache Fetch & Decode Unit Dispatch / Execute Unit Retirement Unit Registers Instruction pool / reorder buffer FetchLoadStore
30
29 Summary Macros Additional Instructions Running a Program Intro to Pentium Systems It wasn’t so bad after all
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.