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

Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

Embed Size (px)

Citation preview

Page 1: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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

Page 2: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

Smile – though your heart is breaking!

Enjoy with study!

Page 3: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

4.7 Program Structure

• Machine lang progs consist of – Code– Data– Stack

• Each part occupies a memory segment

Page 4: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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

Page 5: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

Data segment

• Contains all the variable definitions • Const. definitions too in most cases [cost. defn

– no memory is involved, so anywhere].DATA directive

.DATAHASINA DW 2KHALEDA DW 5ERSHAD EQU 10010001b

; named constants – equates

Page 6: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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

Page 7: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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.

Page 8: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

A simple procedure

name PROC

; body of the procedure

name ENDP ; end procedure

Page 9: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

Defn. of a CODE segment

.CODEMAIN PROC

; main procedure instructions

MAIN ENDP; other procedures go here

Page 10: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

…together! A typical form for SMALL model

.MODEL SMALL

.STACK 100h

.DATA;data definitions go here

.CODE ;SMALL – so no nameMAIN PROC

;instructions go hereMAIN ENDP

;other instructions go here

END MAIN

Page 11: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

4.8 I/O Instructions

• Instructions to access I/O ports directly –– IN– OUT

; provides first I/O; less used

Page 12: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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

Page 13: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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.

Page 14: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

INT int_no.

• int_no. is a number that specifies a routineINT 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

Page 15: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

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. Routine1 single-key input2 single-character output9 character string output

Page 16: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

• INT 21h functions expect input values to be in certain reg. & return output in other reg.

Function 1:Single-key input

Input: AH = 1Output: AL = ASCII code if character key is pressed

= 0 if non-character key is pressed

Page 17: Mid-term Exam Basics & intuitive All materials till-to-date – very simple! Ref. book – Assembly Language Programming and Organization of the IBM PC, by

Function 2:Single-character output / control func.

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

control charOutput: AL = ASCII code of the display char or

control char

Function 2: Some control functions

ASCII Symbol Function7 BEL beep sound8 BS backspace9 HT tab…

Page 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

1st prog!

Q: Read a char – from a keyboard&

display it at the beginning of the next line!