Programming in Module - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Programming in Module

Description:

Computer Organization and Assembly Language #4. C. Vongchumyen ... Attribute for Monochrome. Background. Foreground. Feature. Background. BL R G B. Foreground ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 32
Provided by: kmit
Category:

less

Transcript and Presenter's Notes

Title: Programming in Module


1
Programming in Module
Main call sub1 sub1 sub ax,ax ret
sub1 proc near sub ax,ax ret sub1
endp
sub1 proc Far sub ax,ax ret sub1
endp
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
2
Near Call
Main call sub1 sub1 sub ax,ax ret
sub1 proc near sub ax,ax
ret sub1 endp
Main _at_ 10000H Sub1 _at_ 11002H 11002h-10003h 0FFFH
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
3
Far Call
Main call sub1 sub1 sub ax,ax ret
sub1 proc near sub ax,ax
ret sub1 endp
Main _at_ 10000H Sub1 _at_ 11002H Call _at_ 11000002
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
4
Register Saving
center_cursor proc near push ax push
dx mov ah,2 mov bh,0 mov dh,12 mov
dl,40 int 10h pop dx pop
ax ret center_cursor endp
Set cursor position Int 10H, Function 2 bh
Page number dh Row dl Column
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
5
Multiple file programming
.model small .data public data1 public
data2   data1 db 100 dup (?) data2 db 100 dup
(?)   extrn readnear   .code start mov
ax,_at_data mov ds,ax call read mov ah,4ch mov
al,0 int 21h  END start
.model small .data   extrn data1byte extrn
data2byte   .code   public read   read proc
near mov ah,6 mov al,0ffh int 21h je
read ret read endp   end
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
6
Parameter Passing by Stack
CallProc(i,j,k4)
push I push j mov ax, k add ax, 4 push ax call
CallProc
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
7
Getting Parameter in Stack
CallProc proc near pop RtnAdrs pop
kParm pop jParm pop iParm push
RtnAdrs ..... ret CallProc endp
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
8
Getting Parameter using BP
StdProc proc near push bp mov bp,
sp . mov ax,bp4 Third Parameter mov ax,
bp6 Second Parameter . pop bp ret
StdProc endp
bp2 Rreturn address
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
9
Parameter Passing in Pascal
xyz(a,3,4)
procedure xyz(var iinteger j,kinteger) begin
i jk end Note I -gt pass by
reference J,K -gt pass by value
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
10
Proc xyz(var iinteger j,kinteger)
xyz_i equ 8bp xyz_j equ 6bp xyz_k
equ 4bp xyz proc near push
bp mov bp, sp push es push
ax push bx les bx, xyz_i Get
addr. of I to ESBX mov ax, xyz_j Get J
parameter add ax, xyz_k Add to K
parameter mov esbx, ax Store result
to I para pop bx pop ax pop
es pop bp ret 8 xyz endp
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
11
Using of xyz
mov ax, seg a This parameter is passed by push
ax reference, so pass its mov ax, offset a
address on the stack. push ax mov ax, 3
This is the second parameter push ax mov ax,
4 This is the third parameter. push ax
call xyz
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
12
Interrupt
  • Interrupt Request
  • Interrupt Acknowledge
  • Interrupt Service Routine (ISR)
  • Interrupt V.S. Call
  • Hardware Interrupt (INTR and NMI)
  • Interrupt Vector and Interrupt Vector Table
  • Software Interrupt

C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
13
Interrupt V.S. Call
1)  PUSHF 2)  TF 0 IF 0 3)  Push CS 4)  Push
IP 5) CSIP Addr of ISR
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
14
ISR
SimpleISR proc near cli if reentrance not
allow must place cli hear mov ax,0 iret Si
mpleISR endp
Or using Int 21H Function 25H
mov ax,0 mov es,ax mov ax,esIntNumber4
mov IntVectSave,ax mov ax, esIntNumber42
mov IntVectSave2, ax pushf cli mov word
ptr esIntNumber4, offset SimpleISR mov word
ptr esIntNumber42, seg SimpleISR popf
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
15
DOS Structure
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
16
Cold boot and DOS startup
  • Reset 80x86, All memory is 0, Check parity
  • CSIP FFFF0000 -gt Monitor program (BIOS)
  • BIOS Setup all device and I/O
  • Create Interrupt Vector Table
  • Create Data area 00400000
  • Check boot disk, Load bootstrap loader
  • Load IO.sys, MSDOS.sys
  • Pass control to IO.sys to config device driver
  • Pass control to MSDOS to create DOS function
  • Load Config.sys, Load Command.com
  • Pass controlto Command.com, Load Autoexec.bat
  • Command.com has to part, Resident and Transient
    portion

C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
17
Screen in Text mode
80 Characters 0 79 (0 4FH)
Memory map B8000000
25 Lines 0 24 (0 18H)
Offset 0000 1st Char ASCII 0001 1st Char
Attribute
Position n,m B800(n1602m)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
18
Frequently use of Screen function
Set Cursor Position Input AH 02 BH Page
Number DH Row DL Column Get Cursor
Position and Cursor Size Input AH 03 BH
Page Number Return DH Row DL Column Clear
Screen Input AH 06 AL Number of line
scroll (AL0 mean Full Screen) BH Attribute
CH Start Row CL Start Column DH End
Row DL End Column Set Cursor Size Input AH
1 CH Start line 0-15 CL End Line
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
19
Attribute for Monochrome
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
20
Attribute for Color monitor
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
21
Keyboard
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
22
Keyboard Buffer
ASCII
Scan Code
0000041EH Keyboard Circular Buffer (21
bytes) 0000041AH Keyboard Buffer Head
Pointer 0000041CH Keyboard Buffer Tail Pointer
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
23
Keyboard Status
00000417H
00000418H
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
24
Keyboard Functions
Int 16H
Read Char Input AH 0 Return AH Scan
Code AL ASCII Note Read char from keyboard
buffer, Wait if buffer empty Check Key
Pressed Input AH 1 Return AH Scan Code
AL ASCII Z clear if present Note Not wait
if buffer empty, And not remove key from
buffer Read Status Input AH 2 Return AL
00000417 Note Return and data in
00000417
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
25
Keyboard Functions
Int 16H
Extended Read Char Input AH 10h Return
AH Scan Code AL ASCII Note Same as
Function 00h, But use with 101/102
Keyboard Check Key Pressed Input AH
11h Return AH Scan Code AL ASCII Z
clear if present Note Same as Function 00h, But
use with 101/102 Keyboard Read Status Input
AH 12h Return AL 00000417 Note Same
as Function 00h, But use with 101/102 Keyboard
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
26
Open File
Filename db Filename.txt,0 FileHandle dw
00 lea dx, Filename assume DS Point to
text mov ah, 3dh mov al, 0 int
21h jc OpenError mov FileHandle, ax
Open File Input AH 3Dh AL Open
Mode 0 Read, 1 Write, 2
Read/Write DSDX File name (ASCIIZ) Return
AX File Handle, CF set if Error (call 59H
for Detail)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
27
Create File
Filename db Filename.txt,0 FileHandle dw
00 lea dx, Filename assume DS Point to
text mov ah, 3ch mov cx, 0 int
21h jc CreateError mov FileHandle, ax
Create File Input AH 3Ch CX File
Attribute DSDX File name (ASCIIZ) Return
AX File Handle, CF set if Error (call 59H
for Detail)
Bit Meaning 0 File is a
Read-Only file 1 File is a hidden file 2
File is a system file 3 File is a volume
label name 4 File is a subdirectory 5
File has been archived
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
28
Read File
mov ah,3fh Read data from the file lea dx,
Buffer Address of data buffer mov cx, 1
Read one byte mov bx, FileHandle Get file
handle value int 21h jc ReadError cmp ax, cx
EOF reached? jne EOF mov al, Buffer Get
character read
Read File Input AH 3Fh BX File
Handle CX Number of bytes to read DSDX
Address of Buffer Return AX Number of bytes
read or Error code, CF set if Error
(call 59H for Detail)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
29
Write File
mov ah,40h Write data to the file lea dx,
Buffer Address of data buffer mov cx, 1
Write one byte mov bx, FileHandle Set file
handle value int 21h jc WriteError
Read File Input AH 40h BX File
Handle CX Number of bytes to write DSDX
Address of Buffer Return AX Number of bytes
write or Error code, CF set if Error
(call 59H for Detail)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
30
Close File
mov bx, FileHandle mov ah, 3Eh int 21h
Close File Input AH 3Eh BX File
Handle Return AX Error code, CF set if Error
(call 59H for Detail)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
31
Other function of File
Function 42H Move file pointer 41H
Delete file 39H Create directory 3AH
Remove directory 3BH Change directory 36H
Get disk free space 43H Set or Get file
attribute
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 4
Write a Comment
User Comments (0)
About PowerShow.com