|
查看: 1628|回复: 18
|
谁要.ASM源代码?
[复制链接]
|
|
|
这是Pong游戏,两个人同时用键盘玩。
为了参加比赛,所以指令占用的BYTES越少越好。
- ;
- ; PONG.ASM
- ;
- ; Coded by Boo Khan Ming (Wu), from Malaysia
- ; for Hugi Size Coding Compo 3 (August 1998)
- ;
- ;
- ; Size Distribution 178
- ; 哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪
- ; Ball (clear+draw) 8
- ; Ball (move+reflect+check for end) 41
- ; Bars (clear+draw) 27
- ; Bars (move+kb handler) 38
- ; Misc (init+exit+delay) 46
- ; Text 18
- ;
- ;
- ; This is my first game written in Assembly language.
- ; Please do not expect much from me.
- ; Anyway, I've put great effort in finding the most suitable algorithm,
- ; and this is being my third algorithm.
- ;
- ; 哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪
- ;
- ; There are mainly two unique technique or algorithm employed here and
- ; should be outlined to make you easier to follow the code.
- ;
- ; For keystroke checking, the most essential part is the conversion
- ; performed by AAA (or DAA) instruction.
- ; The player side and the left or right keys are then determined from
- ; bit 0 and bit 1 in accumulator (AL) respectively.
- ;
- ; For ball movement, the horizontal and vertical edge detection are
- ; determined from two counters respectively.
- ; This is concluded from that the number of movement from left edge to
- ; right edge and vice versa are equal. Similarly, the number of movement
- ; from top edge to bottom edge and vice versa are equal too.
- ; Therefore, when the counter are decremented to zero, an edge collision
- ; should be encountered logically.
- ;
- ;
- ; Contact e-mail: bookm@tm.net.my
- ; Homepage URL : http://www.geocities.com/SiliconValley/Horizon/3409/
-
- .MODEL tiny
- .286
- .DATA
- Table DW 0,0
- Message DB "Player 2 has won.$"
- .CODE
- .STARTUP
- mov al, 03h ; set text mode
- int 10h
- push 0b800h ; startup initialization
- pop es
- cli
- lea si, Table ; data table starting offset
- mov di, 324 ; ball parameters
- mov bp, 320
- mov bl, 162
- mov cl, 77
- mov al, 22
-
- Start:
- pusha
- mov ax, 09dch ; draw new ball
- stosw
- mov cl, 75 ; perform vertical retrace
- mov dx, 03dah
- Delay:
- in al, dx
- xor al, cl
- and al, 8
- jnz Delay
- loop Delay
- call Draw ; clear old paddles
- in al, 60h ; check keystroke
- test al, 80h
- jnz Key2
- cmp al, 1 ; (required) to set AF?
- aaa
- mov cl, 10
- mov bl, al
- and bx, 0001h ; determine player side
- shl bl, 1
- test al, 02h ; determine left or right keys
- jnz Key1
- neg cl
- Key1:
- mov ax, [si+bx] ; move paddle
- add al, cl
- cmp al, 90h ; left and right edge check
- jae Key2
- mov [si+bx], ax
- Key2:
- mov ax, 0adbh ; draw new paddles
- call Draw
- popa
- stosw ; clear old ball
- dec di ; move ball
- dec di
- add di, bx
- dec cx ; horizontal edges check
- jnz Move1
- neg bx ; horizontal reflection
- add bx, bp
- mov cl, 79
- Move1:
- dec ax ; vertical edges check
- jnz Move3
- Move2:
- neg bp ; vertical reflection
- add bx, bp
- mov al, 0dbh ; vertical collision check
- scasb
- jnz Stop
- mov al, 22
- dec di
- add di, bp ; vertical reflection correction
- Move3:
- jmp SHORT Start
- Stop:
- shr di, 11 ; update player ID
- sub [si+11], di
- mov al, 03h ; reset text mode
- int 10h
- mov ah, 09h ; display message
- lea dx, Message
- int 21h
- ret
- Draw:
- mov cl, 10 ; draw paddles (procedure)
- push cx
- mov di, [si+2]
- rep stosw
- pop cx
- mov di, [si]
- add di, 0f00h
- rep stosw
- ret
- END
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 7-3-2011 02:17 AM
|
显示全部楼层
厉害下 , 一直想学asm 不过总是感觉很难  |
|
|
|
|
|
|
|
|
|
|
发表于 7-3-2011 01:07 PM
|
显示全部楼层
厉害下 , 一直想学asm 不过总是感觉很难
A-B-C. 发表于 7-3-2011 02:17 AM 
樓主我現在忘記的七七八八了。
據説Visual Studio .NET也有Assembly Language呢,A-B-C.您不妨一試? |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 12:27 AM
|
显示全部楼层
樓主我現在忘記的七七八八了。
據説Visual Studio .NET也有Assembly Language呢,A-B-C.您不妨 ...
FlierMate.. 发表于 7-3-2011 01:07 PM 
哈哈 , 我也想啊 不过还是专注与C++比较好  |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 01:18 AM
|
显示全部楼层
哈哈 , 我也想啊 不过还是专注与C++比较好
A-B-C. 发表于 8-3-2011 12:27 AM 
C++已經很不錯了。 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 01:21 AM
|
显示全部楼层
C++已經很不錯了。
FlierMate.. 发表于 8-3-2011 01:18 AM 
恩 , 不过我还是比较喜欢ASM , 看了王爽的汇编教程 , 不过一直都好像懂一点又不懂一点酱 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 02:02 AM
|
显示全部楼层
恩 , 不过我还是比较喜欢ASM , 看了王爽的汇编教程 , 不过一直都好像懂一点又不懂一点酱
A-B-C. 发表于 8-3-2011 01:21 AM 
很容易的啦,過你幾招:先認識Register:AX,BX,CX....
AX=16bit,EAX=32bit(?) AX=AH(8bit)+AL(8bit)
SET A=1 MOV AX,1
A+=1 ADD AX,1 或 INC AX
SET A=0 XOR AX,AX 或 SUB AX,AX (MOV AX,0好像比較慢,沒有人這樣用)
IF A=3 THEN GOTO R: CMP AX,3
JNZ/JZ R: (我忘了AX=3是ZERO FLAG還是AX=3等於NOT ZERO FLAG)
大概這樣,接下來就是MEMORY部分,有CS,DS。。。都是一pair一pair的,也就是segment, offset。
比如CS是Code Segment,IP(Offset)是Intruction Pointer等等,然後就可以refer去其他Memory區域
記得。COM程序大小不能大過64KB,(現在還是這樣嗎?) 還有可以cast, 比如 MOVE AX,WORD PTR[BL](不太肯定,大概這樣)
還是你看那個筆者的帖比較好。
Microsoft好像用C++開發Windows的哦!C++程序員都很吃香。 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 02:50 AM
|
显示全部楼层
很容易的啦,過你幾招:先認識Register:AX,BX,CX....
AX=16bit,EAX=32bit(?) AX=AH(8bit)+AL( ...
FlierMate.. 发表于 8-3-2011 02:02 AM 
你这样写比较容易明白了 , 因为有时候我理解了add , mov 但是实际运用的时候我就忘了应该用什么命令了 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 02:47 PM
|
显示全部楼层
你这样写比较容易明白了 , 因为有时候我理解了add , mov 但是实际运用的时候我就忘了应该用什么命 ...
A-B-C. 发表于 8-3-2011 02:50 AM 
誇獎了,我比你差,ASM只是咖喱菲,我真正的職業(前幾年)是Visual Basic 6,離C++的地位有天淵之別。
還有那些SHR, SHL, AND, OR, XOR都是High-Level Language都有用到的,所以別怕ASM! |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 07:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2011 09:00 PM
|
显示全部楼层
我只会.....AX,3 INT 10H....
aquamax 发表于 8-3-2011 07:29 PM 
哦,查了查,是80x25 Text Mode吧,我很多程序都在Vista跑不到,因爲這個需要Full Screen!!!而被Vista中止了。 |
|
|
|
|
|
|
|
|
|
|
发表于 11-3-2011 03:11 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 11-3-2011 03:56 PM
|
显示全部楼层
我只会.....AX,3 INT 10H....
aquamax 发表于 8-3-2011 07:29 PM 
弱弱的说.你忘记 MOV AX ,3
INT 10H.
 |
|
|
|
|
|
|
|
|
|
|
发表于 18-3-2011 07:00 AM
|
显示全部楼层
基本上这里头包含了最基本的读key,在垂直扫描返回周期更新画面的部分。。。
是个不错的查考样本,感谢分享。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 19-3-2011 11:02 AM
|
显示全部楼层
忽然想起大学时的assembly programming lab test,
几乎每个星期班上的学生都全军覆没... |
|
|
|
|
|
|
|
|
|
|
发表于 19-3-2011 10:11 PM
|
显示全部楼层
基本上这里头包含了最基本的读key,在垂直扫描返回周期更新画面的部分。。。
是个不错的查考样本,感谢分享 ...
astral 发表于 18-3-2011 07:00 AM 
谢谢你。说不定你比我更懂汇编/组合语言呢! |
|
|
|
|
|
|
|
|
|
|
发表于 19-3-2011 10:12 PM
|
显示全部楼层
忽然想起大学时的assembly programming lab test,
几乎每个星期班上的学生都全军覆没...
AdventChildren 发表于 19-3-2011 11:02 AM 
是电脑工程科系吗?我记得Assembly Language是唯一教到的‘软件’部分。 |
|
|
|
|
|
|
|
|
|
|
发表于 21-3-2011 12:17 AM
|
显示全部楼层
是电脑工程科系吗?我记得Assembly Language是唯一教到的‘软件’部分。
FlierMate__ 发表于 19-3-2011 10:12 PM 
电脑科学的其中一个硬件课,lecturer也是借机会让大家见识见识,没有很认真教... |
|
|
|
|
|
|
|
|
|
|
发表于 27-3-2011 12:14 PM
|
显示全部楼层
忽然想起大学时的assembly programming lab test,
几乎每个星期班上的学生都全军覆没...
AdventChildren 发表于 2011-3-19 11:02 
我是覆没到最后的,幸好retake过关。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|