ENGR 4862 Microprocessors Lecture 11 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

ENGR 4862 Microprocessors Lecture 11

Description:

Affects 6 flags: AF, CF, OF, PF, SF, ZF. Encoding methods ... register AX the contents of location 200H. 2. Add to register AX the contents of location 202H. 3. ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 11
Provided by: lihong2
Category:

less

Transcript and Presenter's Notes

Title: ENGR 4862 Microprocessors Lecture 11


1
ENGR 4862 MicroprocessorsLecture 11
2
Assembly Language Programming
  • Segment definition (full segment definition)
  • The SEGMENT and ENDS directives indicate to the
    assembler the beginning and ending of a segment
  • Three segments code, data, stack
  • Full segment definition vs. Simplified
    segment definition
  • STSEG SEGMENT . STACK 64
  • DB 64 DUP (?)
  • STSEG ENDS . DATA
  • place data here
  • DTSEG SEGMENT data1 DB 25H
  • place data here
  • data1 DB 25H
  • DTSEG ENDS
  • CDSEG SEGMENT .CODE
  • MAIN PROC FAR MAIN PROC FAR
  • ASSUME MOV AX, _at_DATA
  • MOV AX, DTSEG MOV DS, AX
  • MOV DS, AX

3
Assembly Language Programming (II)
  • Code Segment definition
  • The first line of the code segment is the PROC
    directive
  • A procedure is a group of instructions designed
    to accomplish a specific function
  • A code segment may consist of only one procedure,
    but usually is organized into several small
    procedures to make the program more structured
  • Every procedure must have a name defined by the
    PROC directive, followed by instructions and
    closed by ENDP
  • The PROC directive may have the option FAR or
    NEAR
  • DOS requires the entry point to user program be a
    FAR procedure, thus FAR must be used at the
    program entry point

4
Assembly Language Programming (III)
  • It is the job of DOS to assign values for the CS
    and SS registers
  • The DS value (and ES if used) must be initialized
    by the program
  • E.g., MOV AX, OFFSET data or MOV AX, _at_data
  • MOV DS, AX MOV DS, AX
  • The following lines return control to the
    operating system
  • MOV AH, 4CH or INT 6 To Monitor
  • INT 21H To DOS
  • The label for ENDP (MAIN) matches the label for
    PROC. The END directive ends the entire program
    by indicating the entry point MAIN has ended. For
    this reason, the labels for the entry point and
    END must match

5
Programming Example
  • Problem Statement
  • Write an assembly language program to add two
    16-bit numbers that are stored in memory at
    DS200H and DS202H, and store the result in
    DS204H. The original values should not be
    changed
  • Assume the sum will fit in the 16-bit number
  • Use 0100H and 0BCDH as the two numbers

6
Instruction on Intel manual
  • 80x86 does not support memory-memory operation
  • Must go through at least one register
  • Need to look up in the 8086/88 manual for
    instruction
  • ADD instruction (Page 3-64)
  • Affects 6 flags AF, CF, OF, PF, SF, ZF
  • Encoding methods
  • Memory or register operand with register operand
  • Immediate operand to memory or register operand
  • Immediate operand to Accumulator

7
Final Code
Pseudo Code 1. Move to register AX the contents
of location 200H 2. Add to register AX the
contents of location 202H 3. Move to location
204H the contents of AX 4. Exit, Back to DOS
Assembly language MOV AX, 200H ADD AX,
202H MOV 204H, AX MOV AH, 4CH INT 21H
For MS-DOS only!
8
Steps of Creating A Program
  • Edit or create a file using a text editor
  • Assemble the source code into machine code object
    files
  • Link the object files into an executable program
  • Convert the executable to a binary file
  • Download the file
  • Run it!

9
Editor
SAMPLE.ASM
List file shows all opcodes andoffsets, and
locations of errors.
Cross-reference File - list of symbols and labels
Map File - details memory usage
10
.exe vs. .com Files
  • The .exe file can be of any size. Its used
    widely
  • The .com file must fit into a single 64KB segment
  • Very compact
  • To limit the size, data is normally defined
    inside the code segment, also for stack (usually
    at the end area of the code)
  • One of the distinguishing features of the .com
    file is that it has no separate data segment
    definition
  • The other difference is the .com file does not
    have the 512 bytes header block of the .exe file
Write a Comment
User Comments (0)
About PowerShow.com