An Introduction to - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

An Introduction to

Description:

contains an entry for each valid combination of mnemonic and operand(s) used to translate mnemonic into assembly. CS200 Chapter 3. Portland State University ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 35
Provided by: anniegro
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to


1
Chapter 3
  • An Introduction to
  • 8086 Family Assembly Language
  • Programming

2
Review of Registers
  • In EU
  • General purpose registers
  • AX, BX, CX, DX
  • Others
  • SP - Stack Pointer (top of the stack)
  • ST - Status flag
  • BP - Base Pointer, SI - Source Index, DI -
    Destination Index
  • these usually hold the 16 bit offset of a data
    word in one of the segments

3
  • In BIU
  • Segments registers
  • CS, DS, SS, ES
  • Others
  • IP - Instruction Pointer (next instruction in the
    CS)
  • Queue - a set of registers

4
Review of Addressing Modes
  • Immediate - operand is a constant value contained
    in the instruction
  • MOV AX, 0100H
  • Register - operand is an 8-bit or a 16-bit
    register
  • MOV SP, BX
  • Direct - operand is a fixed location in memory
  • MOV CL, 48H
  • MOV 48H, CL

5
Another Addressing Mode
  • Indirect - operand is a memory location
    determined at run-time by using the address
    stored in one or two registers
  • MOV AX, BXSI

6
Program Development Steps
  • Define the problem
  • a statement of purpose
  • Design
  • an algorithm
  • Develop/Implement
  • source code
  • Test
  • test plan

7
Design Approaches
  • Top-Down
  • Break the problem into sub-problems repeat!
  • Bottom-Up
  • Write low-level modules independently, and then
    hope the pieces fit together!
  • Which do you think is better?
  • Which do you think is more common?

8
Representing Your Program
  • Flowcharts
  • use symbols to represent processes, subroutines,
    input output, and decisions
  • Pseudocode
  • any desired program operation can be represented
    by three basic types of operations
  • sequential
  • selection
  • iteration

9
Flowchart Symbols
10
Standard Programming Structures
  • Sequence
  • IF-THEN, IF-THEN-ELSE, CASE
  • WHILE-DO, REPEAT-UNTIL, FOR-DO

11
Types of Assembly Instructions
  • Data Transfer
  • MOV, LEA, PUSH, POP, IN, OUT
  • Arithmetic
  • ADD, SUB, MUL, DIV
  • Bit Manipulation
  • NOT, AND, OR, ROL, SHR
  • String Instructions
  • LODS, STOS, INS

12
  • Program Execution
  • LOOP, JNS, CALL, RET, JMP
  • Processor Control
  • HLT, NOP, STI
  • These are listed in chapter 3 with some detail,
    and in chapter 6 in with great detail
  • Appendix B contains the mnemonics with their
    english translation

13
Coding Template for 8086 Instructions
14
Instruction Coding Examples
  • MOV SP, BX
  • MOV CL, BX
  • MOV CSBX, DL
  • segment override prefix

15
Machine Code Translations
  • This is what an assembler does for us!
  • Very cumbersome
  • Sources for information
  • Chapter 3 has some useful tables
  • Appendix A which has the data sheet for the 8086
  • Appendix B which has templates

16
Assemblers and Assembly Language
  • As weve observed, creating machine code programs
    is tough!
  • Hard to remember numbers for instructions
  • And what about calculating addresses for jumps!
  • Assembly language is the answer (somewhat!)
  • symboliccan use words to represent operations
    and operands
  • low-level
  • each assembly instruction corresponds to one
    machine code instruction
  • translated by an assembler into machine code

17
Two-Pass Assembly
  • Label may be used before it is defined
  • Address which label refers to is unknownforward
    reference
  • CMP DX, BX
  • JLE FISHPOND
  • FISHPOND PUSH AX
  • Two-Pass Assemblers read input file twice to
    overcome this problem

18
Two-Pass Assembly
  • Opcode table
  • contains an entry for each valid combination of
    mnemonic and operand(s)
  • used to translate mnemonic into assembly

19
  • Symbol table
  • holds values of symbols as they are defined
  • two ways to define symbols
  • a label specifying a jump address
  • an explicit definition using a pseudo-op
    (assembler directives)
  • TEMP EQU 2FF0H

20
Two Passes
  • First Pass
  • Build the symbol table
  • scan input file
  • identify labels and pseudo-ops
  • store ltlabel, valuegt pairs in the symbol table
  • Second Pass
  • Generate the machine code output
  • scan input file
  • look-up mnemonics in the opcode table
  • look-up symbols in the symbol table
  • generate machine code output
  • generate reports

21
Language Components of MASM
  • Reserved words
  • Identifiers
  • Predefined symbols
  • Constants
  • Expressions
  • Operators
  • Data types
  • Registers
  • Statements

22
Reserved Words
  • instructions
  • operations the processor can execute
  • directives
  • give commands to the assembler
  • operators
  • used in expressions such as product2
  • predefined symbols
  • return info to your program such as _at_data
  • reserved words are not case sensitive, except for
    the predefined symbols

23
Identifiers
  • a name that you invent and attach to a definition
  • can represent variables, constants, procedure
    names, segment names, and user-defined data types
    such as structures
  • cannot exceed 247 characters
  • the first character can be alphabetic (A-Z), or
    _at_, _ ?
  • the other characters can by any of the above
    characters or a decimal digit (0 - 9)
  • its best to avoid starting an identifier with _at_,
    because many predefined symbols begin with _at_

24
Some Predefined Symbols
  • _at_code
  • returns the name of the code segment
  • _at_data
  • returns the name of the data segment
  • _at_Model
  • returns the selected memory model
  • remember these are caps sensitive!

25
Integer Constants
  • an integer constant is a series of one or more
    numerals followed by an optional radix specifier
  • mov ax, 25
  • mov ax, 0b3h
  • 25 and 0b3h are integer constants..h is a radix
    specifier
  • the default radix is decimal
  • b is for binary
  • d is for decimal
  • h is hex
  • hex constants must start with a decimal digitif
    necessary, add a leading zero

26
Symbolic Constant Expressions
  • You can create symbolic integer constants using
    the EQU directive
  • column EQU 80 Constant - 80
  • row EQU 25 Constant - 25
  • screen EQU column row Constant - 2000
  • you cannot change these!

27
Operators
  • operators are used in expressions
  • expressions are evaluated at assembly time and do
    not change during execution
  • do not confuse with instructions such as ADD,
    MUL, SUB
  • examples
  • screen EQU column row
  • mov amount2, 01dah

28
Data Types
  • DB - type byte (8 bits)
  • myvar DB 20h an 8 bit word named myvar
  • mov ah, myvar move myvar to ah
  • DW - type word (16 bits)
  • mywordvar DW 20afh a 16 bit word named
    mywordvar
  • mov ax, mywordvar move mywordvar to ax
  • DD - type double (32 bits)

29
SEGMENT and ENDS Directives
  • a logical segment is a group of instruction
    statements or data statements contained between
    SEGMENT and ENDS directives
  • similar to the block concept in C
  • DATA_HERE SEGMENT
  • DATA_HERE ENDS

30
Other Directives
  • ASSUME
  • tells the assembler which logical segment to use
    for each physical segment
  • remember that just because I named my data
    segment DATA_HERE, doesnt tell the assembler
    that thats my data segment!
  • ASSUME DSDATA_HERE, CSCODE_HERE
  • segment registers other than the code segment
    must be initialized
  • mov ax, DATA_HERE
  • mov ds, ax

31
MASM Directives
  • .TITLE
  • give the title of the program
  • .DOSSEG
  • use the MSDOS segment order
  • .MODEL small
  • use a small memory model
  • .8086
  • 8086/88 instructions only
  • .STACK 0100h
  • start stack segment and specify size
  • .DATA
  • start data segment
  • .CODE
  • start code segment
  • END
  • tells the assembler to STOP readinganything
    after END will be ignored

32
DOS INT 21H instruction
  • int 21h interrupt program execution
  • 21h specifies that this is a DOS interrupt
  • value contained in ax can determine behavior of
    interrupt
  • mov ah, 9 specify print to stdout
  • mov dx, offset greeting specify what to print
    in dx
  • int 21h
  • mov ax, 4c00h return to DOS
  • int 21h
  • see webpage for complete listing of codes

33
Simple Example I
  • .model small
  • .dosseg
  • .data
  • greeting db 'hello there',13,10,''
  • .code
  • mov ax,_at_data
  • mov ds,ax
  • mov ah,9
  • mov dx,offset greeting
  • int 21h
  • mov ah,4ch
  • int 21h
  • end

34
Simple Example II
.TITLE TEST .DOSSEG .MODEL SMALL .8086 .DATA
multiplicand DW 204AH multiplier DW
3B2AH product DW 2 DUP(0) .CODE
START mov ax, _at_DATA mov ds,
ax mov ax, multiplicand mul
multiplier mov product, ax mov
product2, dx mov ax, 4C00H int
21H END START
Write a Comment
User Comments (0)
About PowerShow.com