Assembly Language

advertisement
Mid-term Exam
• Basics & intuitive
• All materials till-to-date – very simple!
• Ref. book – Assembly Language Programming and
Organization of the IBM PC, by Y. Yu & C. Marut
• Written exam
Smile
– though your heart is breaking!
Enjoy with study!
4.7 Program Structure
• Machine lang progs consist of
– Code
– Data
– Stack
• Each part occupies a memory segment
4.7.1 Mem Models
• .MODEL memory_model ; directive
• Mem. Models 
– SMALL  Code in 1 segment, data in 1 seg.
– MEDIUM  Code in 1+ seg, data in 1 seg
– COMPACT
…
– LARGE …array in max. 64KB
– HUGE
Data segment
• Contains all the variable definitions
• Const. definitions too in most cases [cost. defn
– no memory is involved, so anywhere]
.DATA
directive
.DATA
HASINA
KHALEDA
ERSHAD
DW
2
DW
5
EQU
10010001b
; named constants – equates
Stack segment
• To set a block of memory to store the stack
.STACK
size ; max stack size
; size is optional no.
.STACK
100H
; sets 100h Bytes for the stack area.
; if no size is mentioned – 1 KB is assigned
Code segment
• Contains a program’s instructions
.CODE
name ; name is optional
; NO need for name in SMALL program
- Insides a code segment – instructions are
organized as procedures.
A simple procedure
name
PROC
; body of the procedure
name
ENDP ; end procedure
Defn. of a CODE segment
.CODE
MAIN
PROC
; main procedure instructions
MAIN
ENDP
; other procedures go here
…together!
A typical form for SMALL model
.MODEL
.STACK
.DATA
SMALL
100h
;data definitions go here
.CODE
MAIN
MAIN
END
;SMALL – so no name
PROC
;instructions go here
ENDP
;other instructions go here
MAIN
4.8 I/O Instructions
• Instructions to access I/O ports directly –
– IN
– OUT
; provides first I/O
; less used
2 types of I/O service routines –
1. BIOS [Basic I/O System] routines
 BIOS routines r stored in ROM,
 interact directly with the I/O ports
 see chap. 12.
2. DOS [Disk OS] routines
 can do more complex tasks
INT instruction
• To invoke a DOS or BIOS routine – INT
[Interrupt] instruction is used.
• Interrupt  A signal to a computer that stops
the execution of a running program so that
another action can be performed.
INT
int_no.
INT
int_no.
• int_no.  is a number that specifies a routine
INT 16h
 invokes a BIOS routine that performs keyboard
input
– Chap. 15 for more
INT 21h
 invokes a large no. of DOS functions
– Appendix C for more
INT 21h
(invokes no. of DOS functions)
• A particular function is requested by placing a
function no. in the AH register &
• invoke INT 21h
Function No.
1
2
9
Routine
single-key input
single-character output
character string output
• INT 21h functions expect input values to be in
certain reg. & return output in other reg.
Function 1:
Single-key input
Input: AH
Output:
=1
AL
= ASCII code if character key is pressed
=0
if non-character key is pressed
Function 2:
Single-character output / control func.
Input:
AH
Output: AL
=2
DL
= ASCII code
of the display char or
control char
= ASCII code
of the display char or
control char
Function 2: Some control functions
ASCII
7
8
9
…
Symbol
BEL
BS
HT
Function
beep sound
backspace
tab
1st prog!
Q: Read a char – from a keyboard
&
display it at the beginning of the next line!
Download