A small project to teach myself uses for the stack

Made something in Assembly? Show it off, and tell us how it works...
Absolute beginners welcome... we want to see what you've done!
Forum rules
There is a special rule on this forum...
This forum is intended to offer equal amounts encouragement and constructive feedback...
Therefore, if you say 2 negative things about someones work, you must think of 2 or more equally positive things...

Eg: "Great first effort, the idea is absolutely fascinating... However I noticed a few bugs, and maybe the graphics could be improved..."

If you can't think of anything good to say, then don't say anything!

If we don't encourage newbie programmers they won't have the confidence and motivation to stick at it and become great programmers! *speaking from experience*
Post Reply
EvilSandwich
Posts: 17
Joined: Wed Nov 13, 2019 7:36 am

A small project to teach myself uses for the stack

Post by EvilSandwich » Fri Dec 20, 2019 2:34 am

All this really does is draw a square by drawing one line, storing the pixel location low byte as it does then moving the line down and drawing it backwards by popping the pixel location's low bytes out of the stack.

Again, this is designed for the Easy6502 virtual machine:
http://skilldrick.github.io/easy6502/

Code: Select all

;Initialize Starting Values

LDX #$08	;Setting starting low byte
STX $01

LDX #$03	;Setting Starting high byte
STX $02

LDX #$08	;Setting draw limit

push:		;Starting Push Loop

LDA #$01	;Setting pixel color
STA ($01),y	;Draw Pixel	
TYA		;Transfer Offset to A
PHA		;Push A to Stack
INY		;Increment Offset in Y
CMP #$0f	;Check if Offset = 16
BNE push	;If not, loop again

CLC		;If Offset = 16, ClearCcarry
LDA $01		;Then, Add vertical offset of 32 to Low Byte
ADC #$20
STA $01

pull:		;Starting Pull Loop

PLA		;Popping Offset Value from Stack
TAY		;Transfer Offset from A to Y
LDA #$01	;Resetting Pixel Color
STA ($01),y	;Draw Pixel
CPY #$00	;Check if more Offset Values in Stack
BNE pull	;If not, loop again

CLC		;If Stack is Empty, Clear Carry 
LDA $01		;Then, Add vertical offset of 32 to Low Byte
ADC #$20
STA $01
BCC cdown	;Check if Carry Set
		;If not, Skip incrementing high byte

INC $02		;Increment High Byte

cdown:		;Decrement Draw Limit Count
DEX
BNE push	;If Draw Limit = 0, End
		;Else, Return to Push Loop

BRK		;End
I'm just making this to practice using the stack for programs, since I'm not sure how to use it effectively yet. I know how it works, but I'm still figuring out how to make it useful to me.

FourSeasons
Posts: 16
Joined: Mon Dec 09, 2019 7:38 pm

Re: A small project to teach myself uses for the stack

Post by FourSeasons » Sun Dec 22, 2019 6:34 am

As someone who's not a 6502 expert, it was fun stepping through this in the emulator you linked to.

I'm not used to all this indirect addressed zero page shenanigans, so it took a couple of goes to wrap my head around it. :oops:

Good use of comments and labels, by the way :ThumbsUp

EvilSandwich
Posts: 17
Joined: Wed Nov 13, 2019 7:36 am

Re: A small project to teach myself uses for the stack

Post by EvilSandwich » Mon Dec 23, 2019 9:30 am

Haha thanks. I've gotten some flack for my commenting habits more than once by other 6502 assemblers for being "Overly obvious and redundant".

I just kinda got in the habit of using the comments as a place to write my half baked pseudocode down, hence why so many of them are literal If/Then and If/Else statements.

I've always followed the philosophy that the comment functions of assemblers and compilers exist so the programmer can make it as screamingly plain and obvious as humanly possible to even the most computer illiterate bronze age time traveler what every single part of the code is doing at any given point.

Also for me, because I keep forgetting why I put some code down almost constantly. lol

Post Reply

Return to “Show and Tell”