Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

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 DW 2
KHALEDA DW 5
ERSHAD 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 SMALL
.STACK 100h
.DATA
;data definitions go here

.CODE;SMALL – so no name
MAIN PROC
;instructions go here
MAIN ENDP
;other instructions go here

END 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. Routine


1 single-key input
2 single-character output
9 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 = 1
Output: AL = ASCII code if character key is pressed
= 0 if non-character key is pressed
Function 2:
Single-character output / control func.

Input: AH = 2
DL = ASCII code of the display char or control char
Output: AL = ASCII code of the display char or control char

Function 2: Some control functions

ASCII Symbol Function


7 BEL beep sound
8 BS backspace
9 HT tab

1 prog!
st

Q: Read a char – from a keyboard


&
display it at the beginning of the next line!

You might also like