Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program: powers.s #3

Open
6v6gt-duino opened this issue Feb 11, 2023 · 0 comments
Open

Program: powers.s #3

6v6gt-duino opened this issue Feb 11, 2023 · 0 comments

Comments

@6v6gt-duino
Copy link

6v6gt-duino commented Feb 11, 2023

I've built a simulator of your breadboard CPU as a precursor to adding some real hardware for a hybrid solution, that is a part simulated, part real project. I have a problem with the powers.s program at https://github.com/jamesbates/jcpu/blob/master/programs/powers.s. The Fibonacci and multiplication tables run OK. Obviously, I have considered that I may have made a mistake in emulating your solution but it does look like there is a problem in that powers.s gets stuck in loop0 if the contents of [#0] are greater than 1. I couldn't follow all the logic so I rewrote the program from scratch hoping to be able to recreate the problem but where I could understand how it was supposed to be working. I failed in that the program I constructed worked correctly so I could not reproduce the error. Is there a known problem with powers.s ?

This, incidentally, is the version I created and it works fine

; Ver 12.02.20232 power3_v03.s 
; Show all power series (n^1, n^2, n^3, ...) up to base 15. Limited to 255
; 
;
; core logic: 
; n^E = n^(E-1) * n = n^(E-1) + n^(E-1) .... + n^(E-1) [repeated n times]
; where n is the base and E is the exponent.
; That is, previous displayed power added to itself base-1 times
; gives new displayed power
; Increment exponent until result too big then start with next base.
; Increment base and repeat until > 15.
;
			.org 0
start:			data Rd, #1 
			sto [#0], Rd   	; ram[#0] base = 1  
;
newBase: 		lod Rd, [#0]	; base
			inc Rd		; base++
			sto [#0], Rd    ; base
			data Rb, #15    
			and Rd,Rb       ; test if base outside range 1 to 15 (0x0F)
			jz #start	; base > 15 goto start
			lod Ra, [#0] 	; RegA always holds last calculated power for 
                            		; current base. initial value = base			
;
newExp:			mov Rc, Ra	; last calculated power for current base to accum
			mov Rb, Ra      ; RegB is addend 
			lod Rd, [#0]    ; multiplier (initial value as base - 1 )
			dec Rd          ; multiplier--
;
innerAdd:   		add Rc, Rb	; add old power to self then base-1 more times 
			jc #newBase	; too big so start with next base
			dec Rd		; multiplier--
			jz #showPower   ; multiplier == zero. We have a new power to show 
		    	jmp #innerAdd   ; keep adding base to accum
;			
showPower:		mov Ra, Rc 	; loading to RegA shows it on display	
			jmp #newExp	; next exponent with current base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant