Computer Architecture and Assembly Language Programming (CS401)
Assignment # 4 (Graded) Deadline Date = February 11, 2014
Write a code in assembly language to draw a square in middle of the screen.
Using BIOS video services, the resolution of the screen should be 320x200. The dimension’s length should be 20 pixels. The color of the square should be yellow with black background as shown below:
Solution :
BIOS services are very low level. A level further lower is only directly controlling the hardware. BIOS services provide a hardware independent layer above the hardware and OS services provide another higher level layer over the BIOS services. The layer of BIOS provides services like display a character, clear the screen, etc. All these layers are optional in that we can skip to whatever lower layer we want. BIOS exports its various services through different interrupts. Keyboard services are exported through INT 16, parallel port services through INT 17 and similarly others through different interrupts. The BIOS INT 14 provides serial port services. We will use a mix of BIOS services and direct port access. Important BIOS services regarding the serial port are discussed below.
INT 14 - SERIAL - INITIALIZE PORT
AH = 00h
AL = port parameters
DX = port number (00h-03h)
Return:
AH = line status
AL = modem status
Q program to draw half line
INT 10 - VIDEO - WRITE GRAPHICS PIXEL
AH = 0Ch
BH = page number
AL = pixel color
CX = column
DX = row
Example 12.3
; draw line in graphics mode
[org 0x0100]
mov ax, 0x000D ; set 320x200 graphics mode
int 0x10 ; bios video services
mov ax, 0x0C07 ; put pixel in white color
xor bx, bx ; page number 0
mov cx, 200 ; x position 200
mov dx, 100 ; y position 200
l1: int 0x10 ; bios video services
dec dx ; decrease y position
loop l1 ; decrease x position and repeat
mov ah, 0 ; service 0 – get keystroke
int 0x16 ; bios keyboard services
mov ax, 0x0003 ; 80x25 text mode
int 0x10 ; bios video services
mov ax, 0x4c00 ; terminate program
int 0x21