16/06/13 kiến trúc máy tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)...

44
16/06/13 Kiến Trúc Máy Tính 1

Upload: others

Post on 08-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 1

Page 2: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 2

Page 3: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 3

Page 4: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 4

Page 5: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 5

Page 6: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 6

Page 7: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 7

Page 8: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 8

Page 9: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 9

Page 10: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 10

Page 11: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 11

Page 12: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 12

Page 13: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 13

Page 14: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 14

Page 15: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 15

Page 16: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 16

Page 17: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 17

Page 18: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 18

Page 19: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 19

Page 20: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 20

Page 21: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 21

Page 22: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 22

Page 23: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 23

Page 24: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 24

Page 25: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 25

Page 26: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 26

Page 27: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 27

Page 28: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 28

Page 29: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 29

Page 30: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 30

Page 31: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 31

Page 32: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

Ví dụ 1

include emu8086.inc ORG 100h PRINT 'Hello CDTH14A for Assemble!' GOTOXY 1, 15 PUTC 65 ; 65 - is an ASCII code for 'A' PUTC 'B' Putc 66 putc 'A' RET ; return to operating system. END ; directive to stop the compiler.

16/06/13 Kiến Trúc Máy Tính 32

Page 33: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

Ví dụ 2

name "vga" ; this program draws a tiny rectangle in vga mode. org 100h jmp code ; dimensions of the rectangle: ; width: 10 pixels ; height: 5 pixels w equ 100 h equ 50 ;

16/06/13 Kiến Trúc Máy Tính 33

Page 34: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

set video mode 13h - 320x200 code: mov ah, 0 mov al, 13h int 10h ; draw upper line: mov cx, 100+w ; column mov dx, 20 ; row mov al, 15 ; white u1: mov ah, 0ch ; put pixel int 10h dec cx cmp cx, 100 jae u1 ; draw bottom line:

16/06/13 Kiến Trúc Máy Tính 34

Page 35: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

mov cx, 100+w ; column

mov dx, 20+h ; row

mov al, 15 ; white

u2: mov ah, 0ch ; put pixel

int 10h

dec cx

cmp cx, 100

ja u2

; draw left line:

mov cx, 100 ; column

mov dx, 20+h ; row

mov al, 15 ; white

u3: mov ah, 0ch ; put pixel

int 10h

dec dx

cmp dx, 20

ja u3

16/06/13 Kiến Trúc Máy Tính 35

Page 36: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

; draw right line:

mov cx, 100+w ; column

mov dx, 20+h ; row

mov al, 15 ; white

u4: mov ah, 0ch ; put pixel

int 10h

dec dx

cmp dx, 20

ja u4

16/06/13 Kiến Trúc Máy Tính 36

Page 37: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

; pause the screen for dos compatibility:

;wait for keypress

mov ah,00

int 16h

; return to text mode:

mov ah,00

mov al,03 ;text mode 3

int 10h

ret

16/06/13 Kiến Trúc Máy Tính 37

Page 38: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

Ví dụ 3

name "add-sub"

org 100h

mov al, 5 ; bin=00000101b

mov bl, 10 ; hex=0ah or bin=00001010b

; 5 + 10 = 15 (decimal) or hex=0fh or bin=00001111b

add bl, al

; 15 - 1 = 14 (decimal) or hex=0eh or bin=00001110b

sub bl, 1

16/06/13 Kiến Trúc Máy Tính 38

Page 39: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

; print result in binary:

mov cx, 8

print: mov ah, 2 ; print function.

mov dl, '0'

test bl, 10000000b ; test first bit.

jz zero

mov dl, '1'

zero: int 21h

shl bl, 1

loop print

; print binary suffix:

mov dl, 'b'

int 21h

; wait for any key press:

mov ah, 0

int 16h

ret

16/06/13 Kiến Trúc Máy Tính 39

Page 40: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

Ví dụ 4 name "hi-world"

; this example prints out "hello world!"

; by writing directly to video memory.

; in vga memory: first byte is ascii character, byte that follows is character attribute.

; if you change the second byte, you can change the color of

; the character even after it is printed.

; character attribute is 8 bit value,

; high 4 bits set background color and low 4 bits set foreground color.

; hex bin color

;

; 0 0000 black

; 1 0001 blue

; 2 0010 green

; 3 0011 cyan

; 4 0100 red

; 5 0101 magenta

; 6 0110 brown

; 7 0111 light gray

; 8 1000 dark gray

; 9 1001 light blue

; a 1010 light green

; b 1011 light cyan

; c 1100 light red

; d 1101 light magenta

; e 1110 yellow

; f 1111 white

16/06/13 Kiến Trúc Máy Tính 40

Page 41: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

org 100h ; set video mode mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx, 0 int 10h ; set segment register: mov ax, 0b800h mov ds, ax

16/06/13 Kiến Trúc Máy Tính 41

Page 42: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

; print "hello world"

; first byte is ascii code, second byte is color code.

mov [02h], 'S'

mov [04h], 'a'

mov [06h], 'i'

mov [0ah], 'G'

mov [0ch], 'o'

mov [0eh], 'n'

mov [12h], 'd'

mov [14h], 'e'

mov [16h], 'p'

mov [1ah], 'l'

mov [1ch], 'a'

mov [1eh], 'm'

16/06/13 Kiến Trúc Máy Tính 42

Page 43: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

; color all characters:

mov cx, 15 ; number of characters.

mov di, 03h ; start from byte after 'h'

c: mov [di], 11111100b ; light red(1100) on yellow(1110)

add di, 2 ; skip over next ascii code in vga memory.

loop c

; wait for any key press:

mov ah, 0

int 16h

ret

16/06/13 Kiến Trúc Máy Tính 43

Page 44: 16/06/13 Kiến Trúc Máy Tính 1 · mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) int 10h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003h mov bx,

16/06/13 Kiến Trúc Máy Tính 44