Include

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

.include "m8515def.

inc"

.def RB = R3
.def SK = R4
.def CC = R5
.def ED = R6
.def ANTRE = R7
.def TPA = R8
.def TPB = R9
.def TPC = R10
.def TPD = R11
.def count = R17
.def check = R18
.def temp = R19

START:
ldi R16, low(RAMEND)
out SPL, R16
ldi R16, high(RAMEND)
out SPH, R16

INITIATE_HARGA:
ldi R16, 7
mov RB, R16
ldi R16, 5
mov SK, R16
ldi R16, 5
mov CC, R16
ldi R16, 4
mov ED, R16

MAIN:
ldi R16, 14
mov ANTRE, R16
rjmp ANTREAN

ANTREAN:
cp count, ANTRE
brne CHECK_PUSH
mov count, ANTRE
breq CALCULATE

CHECK_PUSH:
inc count
mov check, count
mov temp, count
andi check, 1
breq PUSH_GENAP_KELIPATAN3
brne PUSH_GANJIL_KELIPATAN_3

PUSH_GENAP_KELIPATAN3:
cpi temp, 3
brsh PUSH_GENAP_KURANG_3
cpi temp, 0
breq PUSH_PAKETC
brne PUSH_PAKETA

PUSH_GENAP_KURANG_3:
subi temp, 3
rjmp PUSH_GENAP_KELIPATAN3

PUSH_GANJIL_KELIPATAN_3:
cpi temp, 3
brsh PUSH_GANJIL_KURANG_3
cpi temp, 0
breq PUSH_PAKETB
brne PUSH_PAKETD

PUSH_GANJIL_KURANG_3:
subi temp, 3
rjmp PUSH_GANJIL_KELIPATAN_3

PUSH_PAKETA:
mov R16, RB
add R16, CC
push R16
rjmp ANTREAN

PUSH_PAKETB:
mov R16, SK
add R16, ED
push R16
rjmp ANTREAN

PUSH_PAKETC:
mov R16, RB
add R16, ED
push R16
rjmp ANTREAN

PUSH_PAKETD:
mov R16, SK
add R16, CC
push R16
rjmp ANTREAN

CALCULATE:
cpi count, 0
brne CHECK_POP
breq FOREVER

CHECK_POP:
mov check, count
mov temp, count
andi check, 1
breq POP_GENAP_KELIPATAN_3
brne POP_GANJIL_KELIPATAN_3

POP_GENAP_KELIPATAN_3:
cpi temp, 3
brsh POP_GANJIL_KURANG_3
cpi temp, 0
breq POP_PAKETC
brne POP_PAKETA

POP_GANJIL_KURANG_3:
subi temp, 3
rjmp POP_GENAP_KELIPATAN_3

POP_GANJIL_KELIPATAN_3:
cpi temp, 3
brsh POP_GANJIL_KURANG_3
cpi temp, 0
breq POP_PAKETB
brne POP_PAKETD

POP_GANJIL_KURANG_3:
subi temp, 3
rjmp POP_GANJIL_KELIPATAN_3

POP_PAKETA:
pop R16
add TPA, R16
dec count
rjmp CALCULATE

POP_PAKETB:
pop R16
add TPB, R16
dec count
rjmp CALCULATE

POP_PAKETC:
pop R16
add TPC, R16
dec count
rjmp CALCULATE

POP_PAKETD:
pop R16
add TPD, R16
dec count
rjmp CALCULATE

FOREVER:
rjmp FOREVER

You might also like