Upload
horace-hunter
View
214
Download
0
Embed Size (px)
Citation preview
1
Segments and Pseudo Operations
Program Development
2
Format of the source code
Each line of code is divided into fields:
Label FieldOperation FieldOperand FieldComment Field
3
Code and Data Segments
We can organize the code into blocks called segments
Segments specify sections of code, data, and reserved areas of memory
Segments are useful for modularized program development
4
Segments
5
Pseudo-Instructions (1) Pseudo-instructions are directives for the Assembler We have already seen some of them
ORG - defines the absolute address of a segmentORG $9000 ;set origin of text segment to $9000
EQU - defines an equivalent symbol for a valueONE EQU $01PORTB EQU $1004
END – delimits the end of the assembly RMB – stands for “reserve memory byte(s)”. It allocates a
specified number of bytes.varname RMB 2
DS – stands for “define space”. It is the same as RMB varname DS 2
6
Pseudo Instructions (2)
FCB – stands for “form constant byte(s)”. It allocates byte(s) of storage with initialized valuesaddrfirstval FCB $01,250,@373,%111001101FCB $23
DB – stands for define byte(s). It is the same as FCB FDB – stands for “form double byte(s)”. It is a 16-bit version of
FCBFDB $0001,$1234,$FFFA
DW – stands for “define word”. It is the same as FDB FCC – stands for “form constant character(s)” and it is used to
allocate and initialize memory for storage of a stringaddrfirstchar FCC “some string”
FCC “Alarm 5A high!”
7
Example
* program to drive a stepper motor
size equ 4PORTB equ $1004 ;PB3-PB0 to stepperorg $9000main ldaa #size
ldx #steps ;address at which $05 is locatedstep ldab 0,x
inxstab PORTB ; step the motordecabne stepbra main
steps fcb 5,6,10,9 ;output sequence
org $FFFEfdb mainend
8
Pseudo Instructions (3)
FILL – sets a number of bytes to a specified valueFILL $FF 16
ZMB – stands for “Zero Memory Bytes” and initialize a specified number of memory bytes to zeroZMB 16
BSZ – stands for “Block Store Zeros and it the same as ZMBBSZ 16
9
Assembly two-pass Process
For an assembler to understand labels and symbols, it must work through the source code twice . It follows as a two-pass process
After the first step the assembler build a “symbol table” that gives the address of each label and symbol.
10
Assembler options and preprocessor directives
Assembler options and preprocessor directives are assembler specific
Assembler options must occur at the beginning of the source code, and start in column one of the code with a $ sign.
The preprocessor directives follows the assembler options and begin with a %. The preprocessor directives tell the assembler to do something before beginning the assembly process%INCLUDE “d:\include\iolib.h”