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

Module Computer System Low- Level Techniques

CT073-3-2

Services
Topic & Structure of The Lesson

• Services

CT073-3-2 and CSLLT Services Slide <2> of 26


Learning Outcomes

At the end of this topic, You should be able to


Understand how DOS/BIOS services work in
an assembly language program

CT073-3-2 and CSLLT Services Slide <3> of 26


Key Terms You Must Be Able To Use

• If you have mastered this topic, you should


be able to use the following terms correctly
in your assignments and exams:
– Services.
– Registers.
– Segment/Offset.

CT073-3-2 and CSLLT Services Slide <4> of 26


Services
What are services?
Predefined functions which have been created by the
computer manufacturer or OS to ease the
programming of a computer. Communication
between the layers is facilitated by the use of
registers.
Application Programs
Operating System
BIOS
Hardware
CT073-3-2 and CSLLT Services Slide <5> of 26
Understanding Registers

CU ALU

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services Slide <6> of 26


Registers - General Purpose

31 16 15 0
EAX AX
EBX BX
ECX CX
EDX DX
ESI SI
EDI DI
CU ALU
EBP BP

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services Slide (7) of 26


Registers - General Purpose

15 8 7 0
AX AH AL
BX BH BL
CX CH CL
DX DH DL

CU ALU

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services Slide (8) of 28


8bit – 16 bit Register Relationship

•. AX = (AH * 256) + AL
• BX = (BH * 256) + BL
• CX = (CH * 256) + CL
• DX = (DH * 256) + DL

CT073-3-2 and CSLLT Services Slide (9) of 26


Registers - Flag Register

31 16 15 0
EFLAG FLAG

CU ALU

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services Slide (10) of 26


Registers - Segment Register
15 0

CS Code

SS Stack

DS Data

ES Extra

FS
GS

CU ALU

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services


Registers - Instruction/Stack
Pointer

31 16 15 0
EIP IP
ESP SP

CU ALU

MEMORY/REGISTERS

CT073-3-2 and CSLLT Services Slide (12) of 26


Services
• The BIOS/OS provide basic services for
the upper layers of the computer to
function and communicate with
external/internal hardware devices.

BIOS
or
As

r am
se

OS
og
mb

Pr
ly

Language

CT073-3-2 and CSLLT Services Slide (13) of 26


Sample Service

Interrupt 21h/Function 02h (DOS)


Display a Character on Screen

Input Call Value


AH 02h
DL ASCII Character Code

Output Return Value


None

CT073-3-2 and CSLLT Services Slide (14) of 26


Sample Service
Interrupt 21h/Function 09h (DOS)
Display String on Screen

Input Call Value


AH 09h
DX String Offset address
DS String Segment address

Output Return Value


None

Comment
The string to be displayed must be terminated with a $ character.
CT073-3-2 and CSLLT Services Slide (15) of 26
Sample Service

Interrupt 21h/Function 01h (DOS)


Read Character from Keyboard - With Echo

Input Call Value


AH 01h

Output Return Value


AL ASCII code

CT073-3-2 and CSLLT Services Slide (16) of 26


Sample Service
Interrupt 21h/Function 0Ah (DOS)
Read String From Keyboard

Input Call Value


AH 0Ah
DS Segment address of buffer/array
DX Offset address of buffer/array

Output Return Value


DS:DX Buffer/array contains the characters read in from the keyboard
(including the carriage return).

Comment
Before calling the service, offset 0 in the buffer must be set with a number
indicating the total characters to be read.
After service returns, offset 1 in the buffer contains the actual number of
characters read in (excluding the carriage return).
CT073-3-2 and CSLLT Services Slide (17) of 26
Sample Service

Interrupt 10h/Function 09h (BIOS)


Display Character on Screen

Input Call Value


AH 09h
AL ASCII Character Code
BH Screen page
BL Character attribute/foreground colour
CX Number of repetitions

Output Return Value


None
CT073-3-2 and CSLLT Services Slide (18) of 26
Sample Service
Interrupt 10h/Function 13h (BIOS)
Display String on Screen
Input Call Value
AH 13h
AL ASCII Character Code
BH Screen Page
BL Character Attribute
CX Length of string without attributes
DH Start Cursor Row
DL Start Cursor Column
BP String Offset
ES String Segment / Extra Segment

Output Return Value


None
CT073-3-2 and CSLLT Services Slide (19) of 26
Sample Service
Interrupt 33h/Function 01h (DOS)
Mouse click detected

Input Call Value


AX 01h ;function to turn mouse on
05h ;function to get mouse button
0002 ; hide mouse cursor, otherwise it will stay on when the
program ends.

CT073-3-2 and CSLLT Services Slide (20) of 26


Example Program

.model small How registers are


.stack 100h setup before the
.code service is called.
MAIN PROC
;****** display a prompt
mov ah,2 ; display a character function
mov dl,'?' ; character ? is displayed
int 21h ; call DOS to display

; ****** end program


mov ah,4Ch ; DOS exit function
int 21h ; exit to DOS
MAIN endp
end MAIN

CT073-3-2 and CSLLT Services Slide (21) of 26


Question

• Write a complete assembly language


program that can perform the following:-
– Display a "?" on the screen.
– Read in a character from the keyboard.
– Create a new line.
– Display the input character on the screen.

Solution
CT073-3-2 and CSLLT Services Slide (22) of 26
Exercise

Through the use of an assembly language, use an appropriate


function to write the following programs.

a) Display an ASCII character on screen using DOS interrupt 21h.


b) Display Character on Screen using BIOS interrupt 10h.
c) Display string on screen using DOS interrupt 21h.
d) Read String from keyboard using DOS interrupt 21h.

CT073-3-2 and CSLLT Services Slide (23) of 26


Summary of Main Teaching Points

• Services are integral in the functioning of


an assembly language program.
• Registers are important storage locations
within the CPU and it is used as a means
of communicating with services.

CT073-3-2 and CSLLT Services Slide (24) of 26


Question and answer session

Q&A

CT073-3-2 and CSLLT Services Slide <25> of 26


What we will cover next

• Representing Data in Assembly Language

CT073-3-2 and CSLLT Services Slide <26> of 26

You might also like