12202021 Kin Trc My Tnh 1 12202021 Kin

  • Slides: 44
Download presentation
12/20/2021 Kiến Trúc Máy Tính 1

12/20/2021 Kiến Trúc Máy Tính 1

12/20/2021 Kiến Trúc Máy Tính 2

12/20/2021 Kiến Trúc Máy Tính 2

12/20/2021 Kiến Trúc Máy Tính 3

12/20/2021 Kiến Trúc Máy Tính 3

12/20/2021 Kiến Trúc Máy Tính 4

12/20/2021 Kiến Trúc Máy Tính 4

12/20/2021 Kiến Trúc Máy Tính 5

12/20/2021 Kiến Trúc Máy Tính 5

12/20/2021 Kiến Trúc Máy Tính 6

12/20/2021 Kiến Trúc Máy Tính 6

12/20/2021 Kiến Trúc Máy Tính 7

12/20/2021 Kiến Trúc Máy Tính 7

12/20/2021 Kiến Trúc Máy Tính 8

12/20/2021 Kiến Trúc Máy Tính 8

12/20/2021 Kiến Trúc Máy Tính 9

12/20/2021 Kiến Trúc Máy Tính 9

12/20/2021 Kiến Trúc Máy Tính 10

12/20/2021 Kiến Trúc Máy Tính 10

12/20/2021 Kiến Trúc Máy Tính 11

12/20/2021 Kiến Trúc Máy Tính 11

12/20/2021 Kiến Trúc Máy Tính 12

12/20/2021 Kiến Trúc Máy Tính 12

12/20/2021 Kiến Trúc Máy Tính 13

12/20/2021 Kiến Trúc Máy Tính 13

12/20/2021 Kiến Trúc Máy Tính 14

12/20/2021 Kiến Trúc Máy Tính 14

12/20/2021 Kiến Trúc Máy Tính 15

12/20/2021 Kiến Trúc Máy Tính 15

12/20/2021 Kiến Trúc Máy Tính 16

12/20/2021 Kiến Trúc Máy Tính 16

12/20/2021 Kiến Trúc Máy Tính 17

12/20/2021 Kiến Trúc Máy Tính 17

12/20/2021 Kiến Trúc Máy Tính 18

12/20/2021 Kiến Trúc Máy Tính 18

12/20/2021 Kiến Trúc Máy Tính 19

12/20/2021 Kiến Trúc Máy Tính 19

12/20/2021 Kiến Trúc Máy Tính 20

12/20/2021 Kiến Trúc Máy Tính 20

12/20/2021 Kiến Trúc Máy Tính 21

12/20/2021 Kiến Trúc Máy Tính 21

12/20/2021 Kiến Trúc Máy Tính 22

12/20/2021 Kiến Trúc Máy Tính 22

12/20/2021 Kiến Trúc Máy Tính 23

12/20/2021 Kiến Trúc Máy Tính 23

12/20/2021 Kiến Trúc Máy Tính 24

12/20/2021 Kiến Trúc Máy Tính 24

12/20/2021 Kiến Trúc Máy Tính 25

12/20/2021 Kiến Trúc Máy Tính 25

12/20/2021 Kiến Trúc Máy Tính 26

12/20/2021 Kiến Trúc Máy Tính 26

12/20/2021 Kiến Trúc Máy Tính 27

12/20/2021 Kiến Trúc Máy Tính 27

12/20/2021 Kiến Trúc Máy Tính 28

12/20/2021 Kiến Trúc Máy Tính 28

12/20/2021 Kiến Trúc Máy Tính 29

12/20/2021 Kiến Trúc Máy Tính 29

12/20/2021 Kiến Trúc Máy Tính 30

12/20/2021 Kiến Trúc Máy Tính 30

12/20/2021 Kiến Trúc Máy Tính 31

12/20/2021 Kiến Trúc Máy Tính 31

Ví dụ 1 include emu 8086. inc ORG 100 h PRINT 'Hello CDTH 14

Ví dụ 1 include emu 8086. inc ORG 100 h PRINT 'Hello CDTH 14 A 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. 12/20/2021 Kiến Trúc Máy Tính 32

Ví dụ 2 name "vga" ; this program draws a tiny rectangle in vga

Ví dụ 2 name "vga" ; this program draws a tiny rectangle in vga mode. org 100 h jmp code ; dimensions of the rectangle: ; width: 10 pixels ; height: 5 pixels w equ 100 h equ 50 ; 12/20/2021 Kiến Trúc Máy Tính 33

set video mode 13 h - 320 x 200 code: mov ah, 0 mov

set video mode 13 h - 320 x 200 code: mov ah, 0 mov al, 13 h int 10 h ; draw upper line: mov cx, 100+w ; column mov dx, 20 ; row mov al, 15 ; white u 1: mov ah, 0 ch ; put pixel int 10 h dec cx cmp cx, 100 jae u 1 ; draw bottom line: 12/20/2021 Kiến Trúc Máy Tính 34

mov cx, 100+w ; column mov dx, 20+h ; row mov al, 15 ;

mov cx, 100+w ; column mov dx, 20+h ; row mov al, 15 ; white u 2: mov ah, 0 ch ; put pixel int 10 h dec cx cmp cx, 100 ja u 2 ; draw left line: mov cx, 100 ; column mov dx, 20+h ; row mov al, 15 ; white u 3: mov ah, 0 ch ; put pixel int 10 h dec dx cmp dx, 20 ja u 3 12/20/2021 Kiến Trúc Máy Tính 35

; draw right line: mov cx, 100+w ; column mov dx, 20+h ; row

; draw right line: mov cx, 100+w ; column mov dx, 20+h ; row mov al, 15 ; white u 4: mov ah, 0 ch ; put pixel int 10 h dec dx cmp dx, 20 ja u 4 12/20/2021 Kiến Trúc Máy Tính 36

; pause the screen for dos compatibility: ; wait for keypress mov ah, 00

; pause the screen for dos compatibility: ; wait for keypress mov ah, 00 int 16 h ; return to text mode: mov ah, 00 mov al, 03 ; text mode 3 int 10 h ret 12/20/2021 Kiến Trúc Máy Tính 37

Ví dụ 3 name "add-sub" org 100 h mov al, 5 ; bin=00000101 b

Ví dụ 3 name "add-sub" org 100 h mov al, 5 ; bin=00000101 b mov bl, 10 ; hex=0 ah or bin=00001010 b ; 5 + 10 = 15 (decimal) or hex=0 fh or bin=00001111 b add bl, al ; 15 - 1 = 14 (decimal) or hex=0 eh or bin=00001110 b sub bl, 1 12/20/2021 Kiến Trúc Máy Tính 38

; print result in binary: mov cx, 8 print: mov ah, 2 ; print

; print result in binary: mov cx, 8 print: mov ah, 2 ; print function. mov dl, '0' test bl, 10000000 b ; test first bit. jz zero mov dl, '1' zero: int 21 h shl bl, 1 loop print ; print binary suffix: mov dl, 'b' int 21 h ; wait for any key press: mov ah, 0 int 16 h ret 12/20/2021 Kiến Trúc Máy Tính 39

Ví dụ 4 name "hi-world" ; this example prints out "hello world!" ; by

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 12/20/2021 Kiến Trúc Máy Tính 40

org 100 h ; set video mode mov ax, 3 ; text mode 80

org 100 h ; set video mode mov ax, 3 ; text mode 80 x 25, 16 colors, 8 pages (ah=0, al=3) int 10 h ; do it! ; cancel blinking and enable all 16 colors: mov ax, 1003 h mov bx, 0 int 10 h ; set segment register: mov ax, 0 b 800 h mov ds, ax 12/20/2021 Kiến Trúc Máy Tính 41

; print "hello world" ; first byte is ascii code, second byte is color

; print "hello world" ; first byte is ascii code, second byte is color code. mov [02 h], 'S' mov [04 h], 'a' mov [06 h], 'i' mov [0 ah], 'G' mov [0 ch], 'o' mov [0 eh], 'n' mov [12 h], 'd' mov [14 h], 'e' mov [16 h], 'p' mov [1 ah], 'l' mov [1 ch], 'a' mov [1 eh], 'm' 12/20/2021 Kiến Trúc Máy Tính 42

; color all characters: mov cx, 15 ; number of characters. mov di, 03

; color all characters: mov cx, 15 ; number of characters. mov di, 03 h ; start from byte after 'h' c: mov [di], 11111100 b ; 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 16 h ret 12/20/2021 Kiến Trúc Máy Tính 43

Thanks See you next Subjects 12/20/2021 Kiến Trúc Máy Tính 44

Thanks See you next Subjects 12/20/2021 Kiến Trúc Máy Tính 44