Title: ICS312 Set 4
1ICS312 Set 4
2Outline 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.)Â
3Program 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
4Program 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.
5Program 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
6Program 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
7Program 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.
8Input 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
9ASCII codes for control characters
10Displaying a String
11Example
- 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.
12HMW 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.
15Textbook Reading (Jones)
Chapter 2 Assembler Overview first part of
Chapter 3