ICS312 Set 4 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

ICS312 Set 4

Description:

... edit first.asm Refer to the instructions on downloading Masm 6.15 on the ... Instructions will be converted into machine code by the assembler ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 16
Provided by: Ruth96
Category:
Tags: masm | assembler | ics312 | set

less

Transcript and Presenter's Notes

Title: ICS312 Set 4


1
ICS312 Set 4
  • Program Structure

2
Outline for a SMALL Model ProgramNote the quiz
at the next lecture will be to reproduce this
slide
.MODEL SMALL .586 allows Pentium
instructions to be used .STACK 100H .DATA 
put data definitions here  .CODE MAIN  PROC 
put instructions for MAIN procedure here MAIN 
ENDP   include additional procedures
after MAIN procedure  SUB1 PROC ... SUB1
ENDP  END MAIN       END directive ends
program              Label used
with END directive matches              
label of first instruction to be
executed in the           
code segment.  (Any legal label can be used.) 
3
Program Structure (1)
Memory Model Use SMALL memory model for
assignments --- creates 1 code segment, 1 data
segment and 1 stack segment. .MODEL
SMALL Processor Directive To use the Pentium
instruction set for PCs, code the 586 processor
directive immediately after the .MODEL
directive Example .MODEL SMALL .586
4
Program Structure (2)
  • Stack Segment
  • Set the stack size to 100h bytes, using
  • .STACK 100h
  • If no stack size is set, the default size is
  • 1000h bytes. A smaller stack size (100h bytes)
  • is more than enough for programs in this
  • course.

5
Program Structure (3)
Data Segment Define all variables in the data
segment, so the memory allocated for them will
be in the program's data area. Different ways
data can be coded Numbers (all converted
into binary) binary numbers with
suffix b, eg 0101101b hexadecimal
numbers with suffix h, eg 3Fh
decimal number Characters Use
single or double quotes eg HI THERE or HI
THERE Variables Variables require that
memory space be allocated for storing values of a
specified data type.  In assembler
programming, a variable's data type
determines the amount of space needed  one byte,
two bytes, 4 bytes, etc. Byte Variables
declared using DB pseudo-opcode Word
Variables (two bytes) declared using DW
pseudo-opcode Double Word Variables (four
bytes) declared using DD pseudo-opcode
6
Program Structure (4)
  • Example of a Data Segment
  • .DATA
  • CRLF   EQU 0DH, 0AH
  • PROMPT DB  'Enter a digit between 0 and 9
  • VAR1   DB  ?
  • ARRAY  DW  1234h, 23h, 0FF54h

7
Program Structure (5)
  • Code Segment
  • The code segment contains all the source code for
    the program.
  • Starts with the directive    .CODE
  • Use procedures to organize the program code
    (example below)
  • Assembly Language Syntax
  • General form of assembly language Instructions
  • name    operation code    operand(s)    
    comment
  • Types of Assembly Language Statements 
  • Instructions - part of the machine language
    instruction set. 
  • Instructions will be converted into machine
    code by the
  • assembler translator.
  • Directives/Pseudo-Operations - directives are
    NOT part of the
  • machine language instruction set and will be
    processed by the
  • assembler translator at assembly time.

8
Input and Output Instructions
Some basic INT 21H Input/Output Functions
  • Examples shown above
  • Read a character from the keyboard
  • Display a character on the monitor

9
ASCII codes for control characters
10
Displaying a String
11
Example
  • Write a program that displays a message on the
    screen.
  • Define the message in the data segment of the
    program.
  • Use LEA Instruction to put the address of the
    message
  • in the DX register. 
  • Display the Message.
  • TITLE SAMPLE PROGRAM
  • .MODEL SMALL
  • .586
  • .STACK 100H
  • .DATA
  • MES DB This is a sample program
  • .CODE
  • MAIN PROC
  • MOV AX, _at_DATA
  • MOV DS, AX
  • MOV AH, 9
  • LEA DX, MES

The portions in the blue boxes will occur in
every main program exactly as shown, except that
the label main (in its three ocurrences) can be
replaced by any other label.
12
HMW Your First Program
  • Write a program to read a character from the
    keyboard
  • and display it at the beginning of the next
    line.
  •  Program outline
  • Display a question mark to prompt for input.
  • Read a character
  • Display the character on the next line
  • save the character in another register
  • move the cursor to the next line (execute
    carriage
  • return and line feed)
  • display the character

13
  • Creating and running your program
  • Create the source file in text format using
    anyword processor. Give it a name with asm
    as suffix, e.g first.asm
  • To use the word processor available in dos,
  • employ edit first.asm
  • Refer to the instructions on downloading Masm
    6.15 on the web page. Assemble andrun first.asm
    as illustrated there, i.e ml first.asm
    first

14
  • Notes
  • For the purpose of readibility, employ function 2
    to output a single character, and function 9 to
    output a string of more than one character
  • You cant assume that the int 21h subroutines
    will preserve the values of al, ax or eax. So
    your code for a new line might wipe out any
    character that you have just read into al.

15
Textbook Reading (Jones)
Chapter 2 Assembler Overview first part of
Chapter 3
Write a Comment
User Comments (0)
About PowerShow.com