Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Eleven on June 08, 2011, 03:02:35 pm

Title: Compile Time error, what is wrong?
Post by: Eleven on June 08, 2011, 03:02:35 pm
hi all, i am new to assambly, was messing around with a little prime-number finder (checks for all numbers 2-->255 if they're prime, and saves them to calculate the next)

spasm keeps giving mee these errors, and i can't find the problem (i use both Hot-Dog's tutorial as the "learn ASM in 28 days"-guide as references, but am still stuck)

the errors:
Code: [Select]
Template.asm:18: error: SUB doesn't take these arguments
Pass two...
Template.asm:12: error: 'primelist' isn't a macro or label
Done
the code
Code: [Select]
#include "ti83plus.inc"                     ; a program that finds all
.org $9D93                                  ; prime numbers up to 255
.db t2ByteTok, tAsmCmp
B_CALL _ClrLCDFull
ld c,1                                  ; c = # known primes
ld b,$FD                                ; b counts from 253->0
outerloop
ld a,b
cpl                                     ; e counts from 2-->255
ld a,e                                  ; and preserves b's cpl
ld b,c
ld hl,primelist                         
innerloop                                 ; we loop through known primes
ld a,(hl)
ld d,a                                  ; d = a known prime 
ld a,e
findrestloop
sub a,d                                 ; finds rest of e/d , ugly but
jr nc findrestloop
add a,d
or a                                    ; a = rest: rest =0 -> e != prime
jr z notprime
inc hl                                  ; next known prime adress
djnz innerloop
prime                                       ;only for reference
ld a,e
ld (hl),a
inc c
ld hl,0                                 ; e is prime, added in next adress
ld l,a
push bc
push de                                 ; save bc and de for later
b_call(_dispHL)                         ; disp found prime
pop de                                  ; de and bc will be needed
pop bc
noprime
ld a,e
cpl                                    ; recall b = cpl e
ld b,a
djnz outerloop                         ; find next prime
ret
primelist                                  ; the list with the primes, starts
.db 2                                      ; with 1 known value: 2

what is wrong?
oh yeah and i know this probably won't be the best solution to the problem, but i just want to experiment a bit with the code.
Title: Re: Compile Time error, what is wrong?
Post by: Runer112 on June 08, 2011, 03:09:10 pm
Hopefully these two things should correct the problems:

Also, I see two more lines that would cause problems, although you haven't discovered that they are in error yet because the assembler didn't get that far. jr nc findrestloop and jr z notprime should have a comma between the condition and the label names to separate the two arguments.
Title: Re: Compile Time error, what is wrong?
Post by: ben_g on June 08, 2011, 03:10:29 pm
sub always substracts from a, so it does only need the register to substract from a

EDIT: ah, nevermind, Runer has already answered that (I was 19 secounds to late)
Title: Re: Compile Time error, what is wrong?
Post by: Mighty Moose on June 08, 2011, 03:10:48 pm
'sub a, d' in line 18 is not an assembly command, it's actually just 'sub d' iirc.
Also, try to end your labels with colons (: ) to avoid compile complications like the one at line 12 (end 'primelist' with a ':' ).

Edit: Dang it, double ninja'd
Title: Re: Compile Time error, what is wrong?
Post by: Eleven on June 08, 2011, 03:54:47 pm
ok that solved it indeed: thanks for quick reply(-ies) =D

still doesnt work as supposed, but i'm gonna try to find that one myself.

thx