Introduction
Hi guys, today I'd to talk about my experience working with assembly language. As the requirement of the lab, I had to build a small program using assembly language. There are a few options that our professor gave us: bouncing graphic, pong, numeric display, and kaleidoscope. I decided to go with kaleidoscope because I have known it for a while.
Process
I'm not used to assembly language and not even a fan of it but here I am. Coding this program took me a lot of time and effort as I need to look up for syntax while planning what to code next. This programming language is indeed the oldest and not user-friendly. However, after days of struggling, I got it up and running in the editor but it still has a few bugs going on here.
As this is quite new to me and not easy to understand at all so I need a lot of time getting used to it but I always try my best. After finishing up, I got a few more ideas of how assembly language code works and more understanding of the syntax as well
define POINTER $10 ; ptr: start of row
define POINTER_H $11
define ROW $20 ; current row
define COL $21 ; current column
define DOT $01 ; dot colour location
define CURSOR $05 ; green colour
setup: lda #$0f ; initial ROW,COL
sta ROW
sta COL
LDA #$01
STA DOT
draw: jsr draw_cursor
getkey: lda $ff ; get keystroke
ldx #$00 ; clear the key buffer
stx $ff
cmp #$30
bmi getkey
cmp #$40
bpl continue
SEC
sbc #$30
tay
lda color_pallete, y
sta DOT
jmp done
continue: cmp #$43
beq clear
cmp #$63
beq clear
cmp #$80
bmi getkey
cmp #$84
bpl getkey
pha
lda DOT
sta (POINTER),y
jsr draw_on_quads
pla
cmp #$80
bne check1
dec ROW
jmp done
check1: cmp #$81 ; right key
bne check2
inc COL ; increment COL
jmp done
check2: cmp #$82 ; down key
bne check3
inc ROW ; increment ROW
jmp done
check3: cmp #$83 ; left key
bne done
dec COL ; decrement COL
clc
bcc done
clear: lda table_low ; clear screen
sta POINTER
lda table_high
sta POINTER_H
ldy #$00
tya
c_loop: sta (POINTER),y
iny
bne c_loop
inc POINTER_H
ldx POINTER_H
cpx #$06
bne c_loop
done: clc
bcc draw
draw_cursor:
lda ROW
and #$0f
sta ROW
lda COL
and #$0f
sta COL
ldy ROW
lda table_low,y
sta POINTER
lda table_high,y
sta POINTER_H
ldy COL
lda #CURSOR
sta (POINTER),y
rts
draw_on_quads:
LDA POINTER
PHA
LDA POINTER_H
PHA
LDA #$10
CLC
SBC COL
CLC
ADC #$10
TAY
LDA DOT
STA (POINTER),y
TYA
PHA
lda #$10
CLC
SBC ROW
CLC
ADC #$10
TAY
lda table_low,y
sta POINTER
lda table_high,y
sta POINTER_H
ldy COL
lda DOT
sta (POINTER),y
PLA
TAY
lda DOT
sta (POINTER),y
PLA
STA POINTER_H
PLA
STA POINTER
RTS
table_high:
dcb $02,$02,$02,$02,$02,$02,$02,$02
dcb $03,$03,$03,$03,$03,$03,$03,$03
dcb $04,$04,$04,$04,$04,$04,$04,$04
dcb $05,$05,$05,$05,$05,$05,$05,$05,
table_low:
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
color_pallete:
dcb $01,$02,$03,$04,$05,$06,$07,$08,$09,$0a
Wrap up
Thank you for reading my blog. After finishing up I have a better understanding of Assembly language but am not very used to it yet. But I'll try my hardest to learn more about it.
Top comments (0)