Similar documents
untitled

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

(2) Function 0BH: Function 0CH: (pixel, picture element) Function 0DH: Function 0FH: Function 13H:

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

幻灯片 1

1

学习MSP430单片机推荐参考书

D/A DAC ( 1us) (10~20 ) DAC0832 1

DPJJX1.DOC

目 录

1 2 / 3 1 A (2-1) (2-2) A4 6 A4 7 A4 8 A4 9 A ( () 4 A4, A4 7 ) 1 (2-1) (2-2) ()

4 / ( / / 5 / / ( / 6 ( / / / 3 ( 4 ( ( 2

Ps22Pdf

微處理機期末專題

Microsoft Word - NHIS2013_C_130716_送印_.doc

C/C++ - 文件IO

数 学 高 分 的 展 望 一 管 理 类 联 考 分 析 第 一 篇 大 纲 解 析 篇 编 写 : 孙 华 明 1 综 合 能 力 考 试 时 间 :014 年 1 月 4 日 上 午 8:30~11:30 分 值 分 配 : 数 学 :75 分 逻 辑 :60 分 作 文 :65 分 ; 总

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

!! "#$%&#%$ ((%)) *++*

. v dx v d () () l s dl s d (_) d () v s v s () a dv a d (_) ( ) ( ) x- = v- = = v 0 = m/s a = = m/s 2 a- = ( ) x- v- a- Page 2 of 20

epub83-1

untitled

Microsoft PowerPoint - os_4.ppt

Ps22Pdf

C/C++ - 字符输入输出和字符确认

1. ( )( ) A. B. C. D. 2. ( )( ) A. : B. : C. : D. : 3. ( )( ) A. : B. : C. : D. : 1 D : 2

7688使用手冊V10.doc

1 CPU


! * # + + *! # $ # #. 1 #! % &)# * 1 *! * ! % # * # * # + + +!!!! # * % # # + # + * & $ *! * # + * # % #& % &* # & # * %! + * # #!

C/C++ - 函数

2/14 Buffer I12, /* x=2, buffer = I 1 2 */ Buffer I243, /* x=34, buffer = I 2 43 */ x=56, buffer = I243 Buffer I243I265 code_int(int x, char *buffer)

1-1 SH79F6431 A. 2( ) 9~15V ( 12V) U2 U3 3.3V SH79F B. 1(VCC/GND) SH79F6431 C. VDDIO SH79F6431 P4 P5 P0.6 P0.7 VDDIO VDDIO=5V D. 2 V 1.0

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

!!"#$ " # " " " " " "$%%& " $%% " "!!

欧洲标准胀紧套

CC213

!!""# $ %#" & $$ % $()! *% $!*% +,-. / 0 %%"#" 0 $%1 0 * $! $#)2 "

Microsoft PowerPoint - C15_LECTURE_NOTE_06

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

第5章:汇编语言程序设计

民 國 105 年 大 專 程 度 義 務 役 預 備 軍 官 預 備 士 官 考 選 簡 章 目 錄 壹 考 選 依 據 1 貳 考 ( 甄 ) 選 對 象 1 參 資 格 規 定 1 肆 員 額 及 專 長 類 別 2 伍 報 名 及 選 填 志 願 日 期 方 式 3 陸 選 填 官 科 (

Microsoft PowerPoint - OPVB1基本VB.ppt

untitled

Ps22Pdf

R/W

Ps22Pdf

bingdian001.com

( )1

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

DR2010.doc

C 1

Epson

SIK) 者, 需 實 施 1 年 以 上, 經 體 格 檢 查 無 後 遺 症 者 5. 身 體 任 何 部 分 有 刺 青 紋 身 穿 耳 洞 者, 不 得 報 考, 各 項 檢 查 結 果 須 符 合 體 位 區 分 標 準 常 備 役 體 位 二 在 校 軍 訓 成 績 總 平 均 70 分

6020

Microsoft PowerPoint - C15_LECTURE_NOTE_06

E170C2.PDF

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

! "! "! # $ # # %#!# $# &# # ()*+, )-.) /# () () 0# 1,2.34, 4*.5)-*36-13)7,) ,9,.).6.(+ :# 13).+;*7 )-,7,<*7,-*=,>,7?#

li 侉 2. 在 下 列 加 点 字 的 正 确 读 音 旁 打 : (1) 我 看 见 路 边 有 一 条 蛇 A.sh 佴 B.sh 佶 C.sh 侑 D.sh 侉 (2) 外 面 的 泥 土 冻 得 很 硬 A.y 侏 n 倮 B.y 侃 n 倮 C.y 佾 n 倮 D.y 佻 n 倮 (3

Microsoft Word - 11.doc


:,,,, ( CIP ) /,. :, ISBN CIP ( 2001) : : 127, : : : ht t p: / / www. nwpup. com : :

E. (A) (B) (C) (D). () () () (A) (B) (C) (D) (E). () () () (A) (B) (C) (D) (E). (A)(B)(C) (D) (E) (A) (B) (C) (D) (E) (A) (B)(C) (D) (E). (A) (B) (C)

2007年普通高等学校招生全国统一考试

C/C++语言 - C/C++数据

2 Keil µ vision 2.1 1) Keil µ vision2 V2.34 µ vision3 2) Sino_Keil.exe Keil c:\keil\ 3) JET51 USB PC C:\Keil\ USB PC 4) S-L

06721 main() lock pick proc() restart() [2][4] MINIX minix2.0 GDT, IDT irq table[] CPU CPU CPU CPU (IDTR) idt[] CPU _hwint00:! Interrupt


untitled


# #$$%& ()*+, -$. #-# / & 0 & 0 #& $& 1 #.& /# 2(3 #$$# $..-$ #$ 0 0 $$$$4 0 0 %# 0-5$ 6 /-0 /0 #$ 0 5$$$ #$$% 0 0 #$$% ()*+, -$. #-# / 7, $8 $$

! " # $ % & (( %) "*+,- &.(/-) & ( 0 & 1! % " % # % & & $ % "/()%!"# (( (02-03 /(((.1/.2( 4 //). /$0 3)0%. /1/%-2 (( ) / ((0 // "*+,- &.(/-) & ( 0 & 1

1 TPIS TPIS 2 2

2006年国家公务员招录考试行测真题(A)

zt

HD61202 HD HD61203 HD61202, HY HY HD61202 HD61202 HD61203 HD =4096 RAMRAM LCD 2HD HD HD /32--

单片机原理及应用实验指导书.doc

<4D F736F F D20C1E3B5E3CFC2D4D8C4A3B0E52E646F63>

穨文件1

instructions.PDF

B. (B) (C) C (D) (E). (Y) (M) (C) (T) (A) (B) (C) (D) (E) Y ( / ) M ( / ) C T ( / ) ( / ) LR=Y(m c) Ytd d 0 : LR=Y(m

TX-NR3030_BAS_Cs_ indd

untitled

General CNC PCU SINUMERIK OP TP SINUMERIK PCU PC USB PC SINUMERIK SINUMERIK PCU SINUMERIK PCU PC SINUMERIK OP SINUMERIK PCU SINUMERIK SINUMERIK PCU MP

99 cjt h 7. 0 (8 ) 0 () abc a b c abc0 aaa 0 a () bca abc0 aa0 a0 0 a0 abc a789 a b c (8 ) 9!

!! "!!"#! # $ %&& ( "! )*+, " - &. - &/%%&& - 0!!$! "$! #$ - -! $$ 12.3! 4)5 %&& &.3 "3!!!!!!!!!!!! &/& - 0.&3.322!!!.! 2&& - 2/& - &362! /&&&//!!! 78

E-BOOK D 本 期 目 录 前 沿 资 讯 丙 泊 酚 与 传 统 镇 静 剂 在 内 镜 逆 行 胰 胆 管 造 影 术 时 的 对 比 研 究 : 一 项 meta 分 析 报 告 2 氯 胺 酮 通 过 减 少 肺 泡 钠 离 子 转 运 而 抑 制 肺 液 体 的

51 C 51 isp 10 C PCB C C C C KEIL

組譯與連結(Ver6

#$%&% () % ()*% +,-. /01 % + (/) " " " 2- %** -340 $%&% 5!$%&% () % ()*% +,-. /01 % + (/) " " " 2- %** -340 /64 7%,(8(, *--9( ()6 /-,%/,65 :$%&

Microsoft Word - 烘焙食品乙級第二部份 doc

# " $ % $ # ( $ $ %% * $ %+ $, -., / ", 0, %, %%%%, " % 2 %% #. $ 3 *3 %45 6" %% 9: :" : "

untitled

untitled

#!$ %" & ( &)*+,((&-,./ )01,+2 ( /., )>2/ 80;2 +&,($ J &( > =.>? =0+ 9, *,0*., 0= )>2/ 2> &02($ J &( > A.;, % 9 > )>* 0= &2 9, )&11.,


V6800/V6600 3D

αlpha-res1000 / αlpha-res1000 / Eutech Eutech Eutech Instruments Pte Ltd EUTECH INSTRUMENTS PTE LTD Blk 55 Ayer Rajah Crescent, #04-16/24, S

Transcription:

42 2141601026 2016 11 27

2 1.1............................................. 2 1.2....................................... 2 1.2.1......................................... 2 1.3............................................. 4 5 2.1............................................. 5 2.2....................................... 5 2.3............................................. 6.......................................... 6 DOS/BIOS 8 3.1............................................. 8 3.2....................................... 8 3.3............................................. 8.......................................... 8 14 4.1............................................. 14 4.2....................................... 14 4.2.1........................................... 14 4.2.2......................................... 15 4.2.3......................................... 15 4.2.4......................................... 15 4.2.5......................................... 17 4.3............................................. 17.......................................... 17 28 5.1............................................. 28 1

1.1 hello, world 1.2 1.2.1 Windows10 Assembler Intel x86 MASM 1 masm32v11r Linker SDK 16 link16.exe Runtime Environment DOSBOX 2 16 0.74 Enhanced Debug Debug 3 C:\masm32\bin DOSBOX C:\Program Files (x86)\dosbox-0.74 DEBUG C:\debug DOSBOX Windows PATH ml dosbox DOSBOX DEBUG DOSBOX PATH DOSBOX DOSBox 0.74 Options.bat autoexec 4 1 MASM: Microsoft Macro Assembler MASM 6 MASM VC MASM SDK http://masm32.com 2 DOSBOX: DOS 16 http://www.dosbox.com 3 DEBUG: https://sites.google.com/site/pcdosretro/enhdebug 4 autoexec DOSBOX 2

3 1.1: DOSBOX AutoExec 1 MOUNT D: C:\ debug 2 SET PATH=D:\ Windows DEBUG DOSBOX D D DOSBOX PATH DOSBOX DEBUG DEBUG main.asm vim 1 $ mkdir 1 2 $ cd 1 3 $ vim main. asm main.asm hello, world 1.2: hello, world 1 option casemap: none 2.model small 3.data 4 hello db 'hello, world$' 5.code 6 main proc far 7 mov ax, @data 8 mov ds, ax 9 mov ah, 09h 10 lea dx, hello 11 int 21h 12 mov ax, 4c00h 13 int 21h 14 ret 15 main endp 16 end main 1.3: Build make.bat 1 $ ml -c *. asm && link16 main.obj, main.exe, nul.map,. lib, nul. def Build make.bat DOSBOX $ dosbox main.exe

4 1.3 DOSBOX MAIN.EXE 1 C:\>MAIN.EXE 2 hello, world INT 21H / AH = 09H

100 7 2.1 2.2 1. 100 7 100 100 2. 7 A 0 7 A i 7 A i+1 = A i + 7 7 7 100 O(n) 3. [0, a] n a = 100, n = 7 735 n a n ( a n + 1) 2 DX, AX 32 2.1: 1 ; unsigned divide 32- bit result by 2 2 shr dx, 1 3 rcr ax, 1 5

6 2.3 2.2: DEBUG: 1 -u 2 06CA:0000 B8CC06 MOV AX,06 CC 3 06CA:0003 8ED8 MOV DS, AX 4 06CA:0005 BA0000 MOV DX,0000 5 06CA:0008 A10600 MOV AX,[0006] 6 06CA:000B F7360800 DIV WORD PTR [0008] 7 06CA:000F BA0000 MOV DX,0000 8 06CA:0012 8BD8 MOV BX, AX 9 06CA:0014 A10800 MOV AX,[0008] 10 06CA:0017 F7E3 MUL BX 11 06CA:0019 43 INC BX 12 06CA:001A F7E3 MUL BX 13 06CA:001C D1EA SHR DX,1 14 06CA:001E D1D8 RCR AX,1 15 -g20 16 AX =02 DF BX =000F CX =002A DX =0000 SP =0000 BP =0000 SI =0000 DI =0000 17 DS =06 CC ES =06 BA SS =06 C9 CS =06 CA IP =0020 NV UP EI PL ZR AC PE NC 18 06CA:0020 B8004C MOV AX,4 C00 19 -g 20 21 Program terminated (0000) 22 -q 06CA:001E (DX AX) 000002DF 16 735 2.3: 100 7 1 option casemap: none 2.model small 3.data 4 a dw 100 5 n dw 7 6.code 7 main proc far 8 mov ax, @data 9 mov ds, ax 10 11 mov dx, 0 12 mov ax, a

7 13 div n 14 15 mov dx, 0 16 mov bx, ax 17 mov ax, n 18 mul bx 19 inc bx 20 mul bx 21 ; unsigned divide 32- bit result by 2 22 shr dx, 1 23 rcr ax, 1 24 25 mov ax, 4c00h 26 int 21h 27 ret 28 main endp 29 end main

DOS/BIOS 3.1 3.2 1. INT 21H / AH = 09H 2. 61H 15.085µs 61H 5 1ms 66 (ms) 3. 42H / 43H 42H 4. INT 16H / AH = 00H 3.3 3.1: 1 PIANO 2 2 3 5 6 7 3 q w e r t y u 4 s d g h j 5 z x c v b n m 6 Press ESC to exit 8

DOS/BIOS 9 3.2: main.asm 1 option casemap: none 2.model small 3.stack 200H 4.data 5 welcome db ' PIANO ', 13, 10 6 db ' 2 3 5 6 7 ', 13, 10 7 db 'q w e r t y u', 13, 10 8 db ' s d g h j ', 13, 10 9 db 'z x c v b n m', 13, 10 10 db ' Press ESC to exit$' 11 12 well dw 262, 1000 13 dw 0, 500 14 dw 262, 1000 15 dw 0, 500 16 dw 294, 2000 17 dw 0, 500 18 dw 262, 2000 19 dw 0, 500 20 dw 349, 2000 21 dw 0, 500 22 dw 330, 4000 23 dw 0, 500 24 dw 0, 0 25 26 keyno db 'zsxdcvgbhnjmq2w3er5t6y7u' 27 fre dw 220, 233, 246, 261, 277, 293, 311, 329, 349, 369, 391, 415 28 dw 440, 466, 493, 523, 554, 587, 622, 659, 698, 739, 783, 830 29 30.code 31 extrn delay: near 32 extrn init: near 33 extrn play: near 34 extrn music: near 35 36 main proc far 37 mov ax, @data 38 mov ds, ax 39 mov es, ax 40 ; display welcome 41 mov ah, 09h

DOS/BIOS 10 42 lea dx, welcome 43 int 21h 44 ; init 45 call init 46 ; well 47 lea dx, well 48 push dx 49 call music 50 pop dx 51 ; keyboard 52 L1S: 53 mov ah, 00h 54 int 16h 55 cmp ah, 01h 56 jz L1E 57 lea di, keyno 58 mov cx, lengthof keyno 59 cld 60 repne scasb 61 jnz L1S 62 mov ax, 1000 63 push ax 64 lea si, fre 65 mov bx, lengthof keyno - 1 66 sub bx, cx 67 shl bx, 1 68 mov ax, [si + bx] 69 push ax 70 call play 71 add sp, 4 72 jmp L1S 73 L1E: 74 mov ax, 4c00h 75 int 21h 76 ret 77 main endp 78 end main 1 option casemap: none 2.model small 3.stack 10 4.code 5 extrn delay: near 6 ; public void init() 3.3: play.asm

DOS/BIOS 11 7 ; init the player 8 public init 9 init proc 10 mov al, 0B6h 11 out 43h, al 12 ret 13 init endp 14 15 ; public void play( int f, int d) 16 ; stack structure 17 ; [bp + 6]: duration dw (ms) 18 ; [bp + 4]: frequency dw (Hz) 19 ; [bp + 2]: caller IP 20 ; [bp + 0]: caller BP 21 public play 22 play proc 23 push bp 24 mov bp, sp 25 ; compute divisor 26 mov dx, 0012H 27 mov ax, 34 DEH 28 mov bx, [bp + 4] 29 div bx 30 ; pass divisor 31 out 42h, al 32 mov al, ah 33 out 42h, al 34 ; turn on 35 in al, 61h 36 mov ah, al 37 or al, 11b 38 out 61h, al 39 ;delay 40 push ax 41 mov ax, [bp + 6] 42 push ax 43 call delay 44 pop ax 45 pop ax 46 ; turn off 47 mov al, ah 48 out 61h, al 49 ; exit 50 pop bp

DOS/BIOS 12 51 ret 52 play endp 53 54 ; public void music( int * music) 55 ; stack structure 56 ; [ bp + 4]: music: the address of music 57 ; [bp + 2]: caller IP 58 ; [bp + 0]: caller BP 59 public music 60 music proc 61 push bp 62 mov bp, sp 63 mov si, [bp + 4] 64 L1S: 65 mov ax, [si + 2] 66 cmp ax, 0 67 jz L1E 68 push ax 69 mov ax, [si] 70 cmp ax, 0 71 jnz T1 72 ; if f == 0 73 call delay 74 add sp, 2 75 jmp T2 76 T1: 77 ; if f > 0 78 push ax 79 call play 80 add sp, 4 81 T2: 82 add si, 4 83 jmp L1S 84 L1E: 85 pop bp 86 ret 87 music endp 88 end 3.4: delay.asm 1 option casemap: none 2.model small 3.stack 6 4.code 5 ; public void delay( times)

DOS/BIOS 13 6 ; delay times in ms 7 ; stack structure: 8 ; [bp + 4]: times 9 ; [bp + 2]: caller IP 10 ; [bp + 0]: caller BP 11 public delay 12 delay proc 13 push bp 14 mov bp, sp 15 push ax 16 push cx 17 push dx 18 19 mov ax, [bp + 4] 20 mov cx, 66 ; 1ms = 66 * 15.085 \ mu s 21 mul cx 22 mov cx, ax 23 ; ( dx cx) cycles, each 15.085 \ mu s 24 L1: 25 in al, 61h 26 and al, 10h 27 cmp al, ah 28 je L1 29 mov ah, al 30 loop L1 31 32 cmp dx, 0 33 jz EXIT 34 dec cx 35 dec dx 36 jmp L1 37 EXIT: 38 pop dx 39 pop cx 40 pop ax 41 pop bp 42 ret 43 delay endp 44 end

4.1 4.2 4.2.1 (Initialization) (Mainloop) INT 10H / AH = 00H AL = 03H 80 25 16 INT 10H / AH = 01H CX = 0100H ( CH > CL ) 4.2.3 4.2.2) 4.1: 1 mainloop: 2 ; display score 3 set_cursor 2, 2 4 PrintString PROMPT1 14

15 5 PrintWordDec score 6 ; display time 7 set_cursor 2, 66 8 PrintString PROMPT2 9 call TimerDisplay 10 ; display player 11 call PlayerDisplay 12 ; call player 13 call PlayerController 14 jmp mainloop 4.2.2 INT 21H / AH = 2CH 4.2.3 INT 10H / AH = 09H 4.2.4 INT 21H / AH = 06H, DL = FFH 4.2: 1 public PlayerController 2 PlayerController proc 3 ; keyboard 4 mov ah, 06h ; direct console input [ or output] 5 mov dl, 0ffh ; for input 6 int 21h 7 ; input router 8 cmp al, 'e' ; e for exit 9 je InputE 10 cmp al, ' ' ; space for shoot ( disappear) 11 je InputSpace 12 cmp al, 4bh ; (left)

16 13 je InputLeft 14 cmp al, 4dh ; ( right) 15 je InputRight 16 ret 17 ; routines 18 InputE: 19 mov ax, 4c00h 20 int 21h 21 ret 22 InputLeft: 23 set_cursor row, col 24 putchar ' ' 25 dec col 26 ret 27 InputRight: 28 set_cursor row, col 29 putchar ' ' 30 inc col 31 ret 32 InputSpace: 33 call shoot 34 ret 35 PlayerController endp INT 10H / AH = 08H 4.3: 1 shoot proc 2 ; generate bullet at ( row - 1, col) 3 mov dh, row 4 mov dl, col 5 dec dh 6 set_cursor dh, dl 7 putchar bullet 8 ; let it fly 9 ; do while 10 flyings: 11 cmp dh, 0 12 jl flyinge ; out of range 13 14 15 set_cursor dh, dl

17 16 putchar ' '; clean old 17 dec dh 18 ; read @bullet judge 19 set_cursor dh, dl 20 mov ah, 08h 21 mov bh, 00h 22 int 10h 23 cmp al, target 24 jnz nothit 25 inc score 26 putchar ' ' 27 ret 28 nothit: 29 30 cmp dh, 0 31 jz flyingt1 32 set_cursor dh, dl 33 putchar bullet 34 push t 35 call delay 36 pop t 37 flyingt1: 38 jmp flyings 39 flyinge: 40 ret 41 shoot endp 4.2.5 2 / : / : e: 4.3

18 4.4: main.asm 1 option casemap: none 2.model small 3 4.data 5 PROMPT1 DB ' SCORE:$' 6 PROMPT2 DB ' TIME:$' 7 8 public score 9 score dw 0 10.stack 200H 11 12.code 13 include macro.inc 14 extrn TimerClear: near 15 extrn TimerPeek: near 16 extrn TimerDisplay: near 17 extrn PlayerController: near 18 extrn PlayerDisplay: near 19 extrn TargetDisplay: near 20 placetarget proc 21 placetarget endp 22 23 main proc far 24 mov ax, @data 25 mov ds, ax 26 ; init 27 clear_screen 1, 1, 23, 78 28 ; 80 * 25 16 colors text video mode 29 mov ah, 0 30 mov al, 03h 31 int 10h 32 ; hide cursor 33 mov cx, 0100h 34 mov ah, 1 35 int 10h 36 call TargetDisplay 37 call TimerClear 38 mainloop: 39 ; display score 40 set_cursor 2, 2 41 PrintString PROMPT1 42 PrintWordDec score 43 ; display time

19 44 set_cursor 2, 66 45 PrintString PROMPT2 46 call TimerDisplay 47 ; display player 48 call PlayerDisplay 49 ; call player 50 call PlayerController 51 jmp mainloop 52 ret 53 main endp 54 end main 1 option casemap: none 2.model small 3.data 4 public target 5 target db 'V' 6 targetcnt dw 7 7 targets db 5, 20, 1 8 db 5, 22, 2 9 db 5, 24, 3 10 db 5, 26, 4 11 db 6, 32, 5 12 db 6, 20, 6 13 db 6, 21, 7 14.code 15 include macro.inc 16 17 public TargetDisplay 18 TargetDisplay proc 19 lea si, targets 20 mov cx, targetcnt 21 L1: 22 push cx 23 mov dh, [si + 0] 24 mov dl, [si + 1] 25 set_cursor dh, dl 26 mov al, target 27 mov bl, [si + 2] 28 mov bh, 0 29 mov cx, 1 30 mov ah, 9 31 int 10h 32 pop cx 4.5: target.asm

20 33 add si, 3 34 dec cx 35 jnz L1 36 ret 37 TargetDisplay endp 38 end 4.6: player.asm 1 option casemap: none 2.model small 3.data 4 row db 22 5 col db 15 6 t dw 100 7 show db 'A' 8 bullet db 1eh 9 extrn target: byte 10 extrn score: word 11.code 12 include macro.inc 13 14 public PlayerController 15 PlayerController proc 16 ; keyboard 17 mov ah, 06h ; direct console input [ or output] 18 mov dl, 0ffh ; for input 19 int 21h 20 ; input router 21 cmp al, 'e' ; e for exit 22 je InputE 23 cmp al, ' ' ; space for shoot ( disappear) 24 je InputSpace 25 cmp al, 4bh ; (left) 26 je InputLeft 27 cmp al, 4dh ; ( right) 28 je InputRight 29 ret 30 ; routines 31 InputE: 32 mov ax, 4c00h 33 int 21h 34 ret 35 InputLeft: 36 set_cursor row, col 37 putchar ' '

21 38 dec col 39 ret 40 InputRight: 41 set_cursor row, col 42 putchar ' ' 43 inc col 44 ret 45 InputSpace: 46 call shoot 47 ret 48 PlayerController endp 49 50 public PlayerDisplay 51 PlayerDisplay proc 52 set_cursor row, col 53 putchar show 54 ret 55 PlayerDisplay endp 56 57 extrn delay: near 58 shoot proc 59 ; generate bullet at ( row - 1, col) 60 mov dh, row 61 mov dl, col 62 dec dh 63 set_cursor dh, dl 64 putchar bullet 65 ; let it fly 66 ; do while 67 flyings: 68 cmp dh, 0 69 jl flyinge ; out of range 70 71 72 set_cursor dh, dl 73 putchar ' '; clean old 74 dec dh 75 ; read @bullet judge 76 set_cursor dh, dl 77 mov ah, 08h 78 mov bh, 00h 79 int 10h 80 cmp al, target 81 jnz nothit

22 82 inc score 83 putchar ' ' 84 ret 85 nothit: 86 87 cmp dh, 0 88 jz flyingt1 89 set_cursor dh, dl 90 putchar bullet 91 push t 92 call delay 93 pop t 94 flyingt1: 95 jmp flyings 96 flyinge: 97 ret 98 shoot endp 99 100 end 4.7: timer.asm 1 option casemap: none 2.model small 3.data 4 Buffer db 4 dup(?) 5 Format db ' 00:00:00', '$' 6 Radix db 10 7.code 8 include macro.inc 9 10 public TimerClear 11 TimerClear proc 12 push ax 13 push cx 14 push dx 15 mov ah, 2ch 16 int 21h 17 mov Buffer[0], ch ; hour 18 mov Buffer[1], cl ; minute 19 mov Buffer[2], dh ; second 20 mov Buffer[3], dl ; (10 ms) 21 pop dx 22 pop cx 23 pop ax 24 ret

23 25 TimerClear endp 26 27 ; return: CH = hour, CL = minute, DH = second, DL = (10 ms) 28 public TimerPeek 29 TimerPeek proc 30 push ax 31 mov ah, 2ch 32 int 21h 33 sub dl, Buffer[3]; 100 34 cmp dl, 0 35 jge T1 36 dec dh 37 add dl, 100 38 T1: 39 sub dh, Buffer[2]; 60 40 cmp dh, 0 41 jge T2 42 dec cl 43 add dh, 60 44 T2: 45 sub cl, Buffer[1]; 60 46 cmp cl, 0 47 jge T3 48 dec ch 49 add cl, 60 50 T3: 51 sub ch, Buffer[0]; 24 52 cmp ch, 0 53 jge T4 54 add ch, 24 55 T4: 56 pop ax 57 ret 58 TimerPeek endp 59 ; display HH: MM: SS format String 60 ; using INT 21H / AH = 09H 61 public TimerDisplay 62 TimerDisplay proc 63 push ax 64 push cx 65 push dx 66 call TimerPeek 67 ; display hour 68 mov ah, 0

24 69 mov al, ch 70 div Radix 71 add ax, 3030h 72 mov Format[0], al 73 mov Format[1], ah 74 ; display minute 75 mov ah, 0 76 mov al, cl 77 div Radix 78 add ax, 3030h 79 mov Format[3], al 80 mov Format[4], ah 81 ; display second 82 mov ah, 0 83 mov al, dh 84 div Radix 85 add ax, 3030h 86 mov Format[6], al 87 mov Format[7], ah 88 ; print 89 PrintString Format 90 pop dx 91 pop cx 92 pop ax 93 ret 94 TimerDisplay endp 95 96 end 4.8: delay.asm 1 option casemap: none 2.model small 3.stack 6 4.code 5 ; public void delay( times) 6 ; delay times in ms 7 ; stack structure: 8 ; [bp + 4]: times 9 ; [bp + 2]: caller IP 10 ; [bp + 0]: caller BP 11 public delay 12 delay proc 13 push bp 14 mov bp, sp 15 push ax

25 16 push cx 17 push dx 18 19 mov ax, [bp + 4] 20 mov cx, 66 ; 1ms = 66 * 15.085 \ mu s 21 mul cx 22 mov cx, ax 23 ; ( dx cx) cycles, each 15.085 \ mu s 24 L1: 25 in al, 61h 26 and al, 10h 27 cmp al, ah 28 je L1 29 mov ah, al 30 loop L1 31 32 cmp dx, 0 33 jz EXIT 34 dec cx 35 dec dx 36 jmp L1 37 EXIT: 38 pop dx 39 pop cx 40 pop ax 41 pop bp 42 ret 43 delay endp 44 end 4.9: macro.inc 1 clear_screen macro op1,op2,op3, op4 2 mov ax,0600 h 3 mov bh,7h 4 mov ch,op1 5 mov cl,op2 6 mov dh,op3 7 mov dl,op4 8 int 10h 9 set_cursor 0, 0 10 endm 11 12 ; ah, bh, dx 13 set_cursor macro row, column 14 mov ah, 02h

26 15 mov bh, 00h 16 mov dh, row 17 mov dl, column 18 int 10h 19 endm 20 21 ; ah, dx 22 PrintString macro string 23 mov ah, 09h 24 lea dx, string 25 int 21h 26 endm 27 28 ; putchar at cursor 29 putchar macro ch 30 mov ah, 09h 31 mov al, ch 32 mov bh, 0 33 mov bl, 0fh 34 mov cx, 1 35 int 10h 36 endm 37 38 putcharcolor macro ch, fg 39 push bx 40 push cx 41 mov ah, 9 42 mov al, ch 43 mov bh, 0 44 mov bl, fg 45 mov cx, 1 46 int 10h 47 pop cx 48 pop bx 49 endm 50 51 52 PrintByteDec macro num 53 mov ah, 0 54 mov al, num 55 _PrintDec 56 endm 57 58 PrintWordDec macro num

27 59 mov ax, num 60 _PrintDec 61 endm 62 63 _PrintDec macro 64 local L1, L2 65 mov dx, 0 66 mov bx, 10 67 mov cx, 0 68 L1: 69 div bx 70 push dx 71 mov dx, 0 72 inc cx 73 cmp ax, 0 74 jne L1 75 L2: 76 pop ax 77 add al, '0' 78 mov dl, al 79 mov ah, 2 80 int 21h 81 dec cx 82 jnz L2 83 endm

C ( ) 5.1 CopyRight 2016 zccz14( ). CC-BY-NC 2.0 L A TEX GitHub GitHub: https://github.com/zccz14/x86assemblyreport 28

1.1 DOSBOX AutoExec.................................... 3 1.2 hello, world............................................ 3 1.3 Build make.bat............................... 3 2.1............................................. 5 2.2 DEBUG:.................................... 6 2.3 100 7................................ 6 3.1........................................ 8 3.2 main.asm.................................... 9 3.3 play.asm................................... 10 3.4 delay.asm................................... 12 4.1.......................................... 14 4.2........................................... 15 4.3....................................... 16 4.4 main.asm................................... 18 4.5 target.asm................................. 19 4.6 player.asm................................. 20 4.7 timer.asm................................. 22 4.8 delay.asm................................. 24 4.9 macro.inc.................................... 25 29