Sign in to follow this  
Leo28C

Assembly lingo?

Recommended Posts

Quick question, guys: Can a normal human being make a simple game such as Pong, Space Invaders, Asteroids, or one of those classics... in pure Assembly language? From the little bit I've seen on it (all I can figure out as of now is the mov instruction) I say no, but what's the most 'advanced' pure ASM game ever done? Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo28C
Quick question, guys: Can a normal human being make a simple game such as Pong, Space Invaders, Asteroids, or one of those classics... in pure Assembly language?
Yes. They certainly all were, so it had better be possible.
Quote:
From the little bit I've seen on it (all I can figure out as of now is the mov instruction) I say no, but what's the most 'advanced' pure ASM game ever done?

Roller Coaster Tycoon was written in assembly.

Share this post


Link to post
Share on other sites
I'm not entirely sure they were all done in assembly. I'm reasonably certain that some of them were done in machine code, and I believe the original version of Ms. Pac Man was done entirely in circuit design. That is to say, there wasn't a general purpose processor for it; the darn thing was custom made just to run the game.

Share this post


Link to post
Share on other sites
O________O
And I thought my Lua clone of Space Invaders was complex...

But what does 'machine code' mean? Please don't tell me someone can understand a program when opened with a hex editor... But if you say circuit design too, I bet it's possible.

*Is excited about learning ASM*

Share this post


Link to post
Share on other sites
I believe the old Elite games were written in assembly. Now THAT must have been a monumental task. So yes, you could do anything in assembly that you could in any other language. It's just a question of how much work is involved :) .

Personally though, I refuse to touch assembly. a) I'm not a masochist and b) I'd only ever use it if I absolutely had to do something really low level, like create a device driver. For general programming, I'm not naive enough to think I could use it to create code that's more optimized than what modern compilers already produce. Add to that reduced readability and portability? No thanks :)

Share this post


Link to post
Share on other sites
Using assembly? Borderline waste of time because you're increasing development time of the code by an order of magnitude or more for a very tiny benefit.

Learning assembly? I'd say extremely useful, so that you have a better idea as to what your code is doing after compilation.

Quote:
Quick question, guys: Can a normal human being make a simple game such as Pong, Space Invaders, Asteroids, or one of those classics... in pure Assembly language?

All they had at the time was basically assembly language. One benefit of ASM is that you can squeeze out as much speed as possible with enough time. Back in the 70s, hardware was horifically slow, and any higher level language likely wouldn't compile well enough to work. Here's an excerpts from the wiki page on the 2600 that might give you some idea as to how weak it was:
Quote:
The CPU was the MOS Technology 6507, a cut-down version of the 6502, running at 1.19 MHz in the 2600.
...
The console had only 128 bytes of RAM for runtime data that included the call stack and the state of the game world. There was no frame buffer, as the necessary RAM would have been too expensive. Instead the video device had two bitmapped sprites, two one-line "missile" sprites, a one-pixel "ball," and a "playfield" that was drawn by writing a bit pattern for each line into a register just before the television scanned that line. As each line was scanned, a game had to identify the non-sprite objects that overlapped the next line, assemble the appropriate bit patterns to draw for those objects, and write the pattern into the register. By default the right side of the screen was a duplicate of the left; to control it separately, the software had to modify the patterns as the scan line was drawn. After the controller scanned the last active line, a more leisurely vertical blanking interval began, during which the game could process input and update the positions and states of objects in the world. Any mistake in timing produced visual artifacts, a problem programmers called racing the beam.

Share this post


Link to post
Share on other sites
Regards the original question :
Yes, it is possible to write a full game in assembly language. dont forget that a C/C++ compiler 'compile' your C/C++ files to a assembly code / machine code.

Should we write a pure asm game ? only if you want to challange yourself. even in the 80/90 when assembly was required to get decent frame rates, only rare games were programmed only in assembly language. most of the games had their engine use alot of assembly language for optimization but the game logic were all developed in high level language.

Should you learn assembly ? I would say hell yes !. understand your machine assembly code will help you in many cases. a big help would be to help you find some internal bugs. dissasembly your code sometimes just show you the bugs. it can be very useful when writing in C++, because C++ hide some of its work from the user.

Because I am in the low level programming, I have found tons of other uses to assembly. mostly in understanding what the system does. sometimes even to find a bug in the core of the operating system.

Nuno1

Share this post


Link to post
Share on other sites
I never would have gotten into programming if it was all assembly, punch cards, circuits, or any of that other low level stuff when I went to school. I just don't have the patience to dick around with that kind of punishment.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cypher19
Using assembly? Borderline waste of time because you're increasing development time of the code by an order of magnitude or more for a very tiny benefit.
Borderline waste? Total waste! Tiny benefit? Much [MUCH] more often than not, NO benefit! [huge detriment would be a more accurate means of describing the preference for hand-tuned over compiler-tuned code]

Frankly, the only reason to do assembly these days is to get access to functionality that isn't exposed through native language primitives. Commands like CAS and LL/SC are damn useful, as are certain old memory move commands, yet contain meaning that isn't expressed by any higher-level command. With the exception of that though, top-of-the-line compilers are sophisticated enough these days to code circles around 99% of programmers [99% being the conservative estimate put in place because '100%' would result in people finding crumby compilers that they can outperform with hand-tricked code].

Assembly for general purpose though? Learn what it is, what it does, and why you shouldn't use it...

Then don't use it.

Glance at it, and don't use unless you can't do something without it [note the wording 'CANT do something without it', not 'think you can do better']

Share this post


Link to post
Share on other sites
Well this source code for pong in assembly says it can:

;------------ INITIALIZATION -----------;

VSeg EQU 0A000h

JMP start

OldVidMode DB ?
PaddleX DW 160
BallX DW 160
BallY DW 100
BallDX DW 1
BallDY DW -1
BallCounter DB 3
start:

; Store old video mode
MOV AX, 0F00h
INT 10h
MOV OldVidMode, AL

; Set new video mode
MOV AX, 0013h
INT 10h

CALL Main

;CALL WaitKey

; Restore old video mode
MOV AH, 00h
MOV AL, OldVidMode
INT 10h

; Terminate program
MOV AX, 4C00h
INT 21h


;----------- SUBROUTINES ----------;


WaitKey:
MOV AH, 06h
MOV DL, 0FFh
WK_loop:
INT 21h
JZ WK_loop
RET


Main:

;MOV AX, 0001h
;INT 33h

MOV AX, 000Bh
INT 33h

MainLoop:

CALL Update

CALL ClearBuf
CALL Draw
CALL Blit

; Check for a keystroke
MOV AH, 06h
MOV DL, 0FFh
INT 21h
JZ MainLoop ; No Keystroke? Jump to start

RET

ClearBuf:
MOV CX, 320 * 200
MOV ES, CS
MOV DI, OFFSET VidBuf
CLD
MOV AL, 0
REP STOSB
RET

Blit:
MOV CX, 320 * 200
MOV ES, VSeg
MOV DI, 0
MOV DS, CS
MOV SI, OFFSET VidBuf
CLD
REP MOVSB
RET

Draw:

; Draw player paddle
MOV AX, PaddleX
MOV BX, 64000 - 960
CALL DrawPaddle

; Draw Computer paddle
MOV AX, BallX

CMP AX, 16
JGE PaddleLeftGood
MOV AX, 16
PaddleLeftGood:

CMP AX, 320-16
JLE PaddleRightGood
MOV AX, 320-16
PaddleRightGood:

MOV BX, 0
CALL DrawPaddle

; Draw Ball
CALL DrawBall

RET


DrawPaddle:
MOV ES, CS
MOV DI, OFFSET VidBuf
ADD DI, AX
SUB DI, 16
ADD DI, BX
MOV CX, 32
MOV AL, 2
REP STOSB
MOV CX, 32
ADD DI, 320 - 32
REP STOSB
MOV CX, 32
ADD DI, 320 - 32
REP STOSB
RET

DrawBall:
MOV ES, CS
MOV DI, OFFSET VidBuf
MOV AX, BallY
IMUL AX, 320
ADD AX, BallX
ADD DI, AX
SUB DI, 320 + 1

MOV CX, 3
MOV AL, 3
REP STOSB
MOV CX, 3
ADD DI, 320 - 3
REP STOSB
MOV CX, 3
ADD DI, 320 - 3
REP STOSB
RET

Update:

; ------ Upate Player Paddle ------ ;

; Get Relative Mouse movement
MOV AX, 000Bh
INT 33h
ADD PaddleX, CX

CMP PaddleX, 16
JGE NoFixRight
MOV PaddleX, 16
NoFixRight:
CMP PaddleX, 320 - 16
JLE NoFixLeft
MOV PaddleX, 320 - 16
NoFixLeft:

DEC BallCounter
CMP BallCounter, 0
JZ BallNeedUpdate
RET
BallNeedUpdate:
MOV BallCounter, 3

; ------- Update Ball --------------- ;
MOV AX, BallX
ADD AX, BallDX
MOV BallX, AX

MOV AX, BallY
ADD AX, BallDY
MOV BallY, AX

CMP BallX, 1
JGE BallLeftGood
MOV BallX, 1
NEG BallDX
BallLeftGood:

CMP BallX, 320-1
JLE BallRightGood
MOV BallX, 320-1
NEG BallDX
BallRightGood:

CMP BallY, 4
JGE BallTopGood
MOV BallY, 4
NEG BallDY
BallTopGood:

CMP BallY, 200-4
JLE BallBotGood

MOV AX, BallX
SUB AX, PaddleX
CMP AX, 18
JLE NotMissedRight
CALL ResetBall
JMP BallBotGood

NotMissedRight:
CMP AX, -18
JGE DoneBall
CALL ResetBall
JMP BallBotGood

DoneBall:
MOV BallY, 200-4
NEG BallDY
BallBotGood:

RET

ResetBall:
MOV BallX, 160
MOV BallY, 100
MOV BallDX, 1
MOV BallDY, -1
RET

VidBuf DB


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this