Assembly Language - Microprocessors and Computer Systems - Lecture Slides, Slides of Microprocessors

The course is to provide both theoretical background and practical skills in microcomputer (x86) system design. Both hardware and software development (assembly language) and debugging tools are included in the laboratory experiments. Key points in this lecture are: Assembly Language, Instruction Set, Programming in 8088 and 8086, Machine Languages, Assemblers, Program Trapping, Tracing, Fields in Assembler, Assembly Language Programs, Advantages of High-Level Languages

Typology: Slides

2012/2013

Uploaded on 09/28/2013

noob
noob 🇮🇳

4.4

(25)

105 documents

1 / 77

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assembly Language &
Instruction Set
(Hall: Ch3; Brey: Ch8-1; Triebel: Ch3)
(Brey: Ch4-6; D. Hall: Ch6)
ELEG 3230B
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d

Partial preview of the text

Download Assembly Language - Microprocessors and Computer Systems - Lecture Slides and more Slides Microprocessors in PDF only on Docsity!

Assembly Language &

Instruction Set

(Hall: Ch3; Brey: Ch8-1; Triebel: Ch3)

(Brey: Ch4-6; D. Hall: Ch6)

ELEG 3230B

Programming in 8088/

 Three levels of languages available to program a microprocessor: Machine Languages , Assembly Languages , and High-level Languages.  Machine Language  A sequence of binary codes for the instruction to be executed by microcomputers.  Long binary bits can be simplified by using Hexadecimal format.  It is difficult to program and error prone.  Different uP (micro-processor) uses different machine codes. Example: Memory Address^ Contents (binary)^ Contents (hex)^ Operation 00100H 00101H 1110010000000101 E4 05 INPUT FROMPort 05H 00102H 00103H 0000010000000111 0407 ADD07H 00104H 00105H 1110011000000010 E6 02 OUTPUTOPORT 02

Machine Code

Assemblers

 Programming the instructions directly in machine code is possible but very time consuming as each basic instruction can have one of several different machine codes depending on how the data is stored.  The process of converting the microprocessor instructions to the binary machine code can be performed automatically by a computer program, called an ASSEMBLER. Popular assemblers include IBM macro Assembler, Microsoft Macro Assembler (MASM) and Borland Turbo Assembler (installed on IE NT Network).  Most assemblers accept an input text file containing lines with a rigorously defined syntax split into four fields.

 Not all fields need to be present in a line. Eg. A line can be just a comment line if it starts with semicolon;

Label Mnemonic/directive Operands comment FRED: ADD AL,0FH ;Adds 0FH to register AL

Program Trapping (Tracing)

 Most microprocessors have a mode of operation which allows a program to be stopped after each instruction and the execution of another program (debugging program) to allow program debugging (examining the operation of a program to find errors [bugs]).  Debugging mode is entered by setting the T (trap) flag in the FLAGS register of the Intel 80 X 86 (or the trace flag in the status register of the Motorola 68000 ). ( check ex. 12 - 1 of Brey‟s)  Typical debugging methods  Single instruction stepping (time (^) consuming)and examine the register and memory contents after each  Program the program) tracing (i.e. finding the sequence of instructions being executed by  Breakpoints allow examination (stopping of the a registers)program at a point decided by the programmer to  Memory dump (outputting the contents of memory)

Fields in Assembler (cont.)

 Mnemonic/directive field contains the abbreviation for the processor instruction (eg. MOV) or an assembler DIRECTIVE. A directive produces no object code but is used to control how the assembler operates. Examples of directives include END - indicate the end of a program listing, FRED LABEL NEAR - define “FRED” as a near label TOM EQU 1000H - define “TOM” as the number 1000H

 Label field contains a label which is assigned a value equal to the address where the label appears.

Assembly Language Programs

 Writing assembler program takes longer time than programming in a high level language like C.

Example: Two long integers may be added in C language by A similar addition in X=Y+ZAssembly; needs 6 lines : ; ; Assumethree memory the three locations numbers [X],[Y],[Z] are referenced at MOV AX, [Y] ; load from address [Y] into register AX MOV DX [Y+ 2 ] ; load high-order word to DX ADD AX, [Z] ; add low-order word; ADC DX, [Z+ 2 ] ; add with carry high-order word; MOV [X], AX ; store result at memory address X MOV [X+ 2 ], DX replaced with two numbers representing the offset address in a real program.^ Note: [x] and [y] are not of proper format in assembly; x and y should be

Advantages of High-level languages

 Block structure code broken into “logical blocks” that perform specific function.: programs are most readable when they are

 Productivity: easier to program

 Level of complexity: no need to know the hardware details

 Simple mathematics formula statement available

 Portability: only need to change the compiler when it is ported to other

machine

 Abstract data types record and array, and high precision value.: different data types like floating-point value,

 Readability

Actually you can incorporate Assembly programs in C/C++

( check out Brey Ch.7)

Intel 8088/8086 Instruction Set Overview

 Intel 8088 has ninety basic (ie not counting addressing mode

variants) instructions

 Instructions belong to one of the following groups: data

transfer , arithmetic , logic , string manipulation , control

transfer and processor control.

Instruction Set (cont.)

 Microprocessors can perform a range of basic operations defined by their instruction set  The instruction set is a set of binary codes known as op-codes which can be decoded by the microprocessor‟s control unit  Op-codes are often combined with some address information to specify the location of the operands (the data for the instruction) 7 0 7 0 7 0

op-code data/address data/address

Instruction^ Example machine code instruction machine code

IN AL,05h  E 05

Increase in memory address

Intel 8088 Machine Code Instruction Format

 Machine code for an instruction consists of a binary code of variable length (typically 2 bytes, but can be 1 byte to 4 bytes depending on the instruction). Machine code includes all the necessary information (opcode, address, data) for an instruction  The machine codes for the Intel 8088 is listed in the Intel Microprocessor data book.  Example : Move and Jump instructions (pp47 Hall‟s)(Brey‟s ch4-1)

Instructions Set

Also from http://www.emu8086.com/assembly_language_tutorial_assembler_reference/8086_instruction_set.html

ELEG 3230B - Part 6

Data Transfer (14) MOV, PUSH, POP, XCHG, IN, OUT, XLAT, LEA, LDS, LES, LAHF, SAHF, PUSHF, POPF Arithmetic (20) ADD, ADC, INC, AAA, BAA, SUB, SSB, DEC, NEG, CMP, AAS, DAS, MUL, IMUL, AAM, DIV, IDIV, AAD, CBW, CWD Logic (12) NOT, SHL/SAL, SHR, SAR, ROL, ROR, RCL, RCR, AND, TEST, OR, XOR String Manipulation (6) REP, MOVS, XMPS, SCAS, LODS, STOS Control Transfer (26) CALL, JMP, RET, JE/JZ, JL/JNGE, JLE/JNG, JB/JNAE, JBE/JNA, JP/JPE, JO, JS, JNE/JNZ, JNL/JGE, JNLE/JG, JNB/JAE, JNBE/JA, JNP/JPO, JNO, JNS, LOOP, LOOPZ/LOOPE, LOOPNZ/LOOPNE, JCXZ, INT, INTO, IRETR Processor Control (12) CLC, CMC, STC, CLD, STD, CLI, STI, HLT, WAIT, ESC, LOCK, NOP

Intel 8088/8086 Instruction Set Overview

Data Movement Instructions (cont.)

LAHF - loads the low-order bytes of the FLAGS register to AH SAHF - stores AH into the low-order byte of FLAGS PUSHF - copies the FLAGS register to the stack POPF - copies a word from the stack to the FLAGS register

Instructions for moving strings String instructions are repeated when prefixed by the REP mnemonic (CX contains the repetition count) MOVS d,s - (MOVSB, MOVSW) memory to memory data transfer LODS s - (LODSB and LODSW) copies data into AX or AH STOS d - (STOSB, STOSW) stores data from AH or AX

ELEG 3230B - Part 6

Data movement using MOV MOV d,s d=destination (register or effective memory address), s=source (immediate data, register or memory address)  MOV  any register to any register (except CS register) can transfer data from:   memory to any register (except CS)immediate operand to any register (except CS)   any register to a memory locationimmediate operand to memory  MOV intermediate storage). cannot perform memory to memory transfers (must use a register as an  MOV and destination operands must have the same bit length. moves a word or byte depending on the operand bit-lengths; the source  MOV cannot be used to transfer data directly into the CS register.  Typical number of clock cycles to carry out MOV are 2 clocks for register-register 4 clocks for immediate-register 8+ea clocks for memory-register (8086) 12+ea clocks for memory-register (8088)

clock cycle: in part 08. will be discussed ea: a value depends on effective address