Jump to content

Hey guys, I have an issue and I can't seem to notice the problem.

The program should take the two binary numbers that enter through PORT B (numa RB0-RB2 and numb RB4-RB6) add them and then display the result through PORTA so that a 2, 7 digit display can read (RB3 and RB7 are used to activate them in sequence as the corresponding numbers are loaded to PORTA.

	list	p=16f627a
	#include<p16f627a.inc>
	cblock	H'20'
CounterA,CounterB,CounterC,numa,result,unidad,decena
	endc
	org	h'00'
	goto inicio
tabla
	addwf	PCL,f
	retlw	b'01011111'
	retlw	b'00000110'
	retlw	b'10011011'
	retlw	b'10001111'
	retlw	b'11000110'
	retlw	b'11001101'
	retlw	b'11011101'
	retlw	b'00000111'
	retlw	b'11011111'
	retlw	b'11001111'
delay
		movlw	D'7'
		movwf	CounterB
		movlw	D'125'
		movwf	CounterA
loop
		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		retlw	0
principal
	movlw	d'9'
	movwf	result
	movlw	d'10'
	subwf	result,w
	btfsc	STATUS,C
	goto	mayor
	goto	menor
mayor
	movwf	unidad
	movlw	d'1'
	movwf	decena
	goto	mostrar
menor
	movf	result,w
	movwf	unidad
	movlw	d'0'
	movwf	decena
mostrar
	movf	unidad,w
	call	tabla
	movwf	PORTA
	bsf		PORTB,3
	call	delay
	bcf		PORTB,3
	movf	decena,w
	call	tabla
	movwf	PORTB
	bsf		PORTB,7
	call	delay
	bcf		PORTB,7
	goto	principal
inicio
	movlw	h'07'
	movwf	CMCON
	bsf		STATUS,5
	movlw	H'77'
	movwf	TRISB
	clrf	TRISA
	bcf		STATUS,5
	clrf	unidad
	clrf	decena
	clrf	PORTB
	clrf	PORTA
	clrf	numa
	clrf	result
	goto	principal
	END

At first, nothing worked, so I dicided to reduce the code to eliminate variables. I just coded for it to display a 9, but it somewhy just displays a 99, ignoring to change the PORTA to the 0

 

 

 

Case: NZXT phantom CPU:I5-4460 GPU:MSI-GTX1070 Gaming X RAM:2x4Gb-DDR3-HyperX fury MOBO:Asus Z97-P HDD:Toshiba 1Tb 7200rpm PSU:Sentey650W

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/
Share on other sites

Link to post
Share on other sites

I'm confused as to what sort of assembly this even is, especially the goto which doesn't appear to have any well-defined conditions, but would cause an infinite loop if it didn't.

 

It looks like you're probably decrementing and overflowing down based on the loop logic.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8652572
Share on other sites

Link to post
Share on other sites

37 minutes ago, patrickjp93 said:

I'm confused as to what sort of assembly this even is, especially the goto which doesn't appear to have any well-defined conditions, but would cause an infinite loop if it didn't.

 

It looks like you're probably decrementing and overflowing down based on the loop logic.

I don't know what you mean, It's assemler, we use it to program microchips's PIC16f627a

Case: NZXT phantom CPU:I5-4460 GPU:MSI-GTX1070 Gaming X RAM:2x4Gb-DDR3-HyperX fury MOBO:Asus Z97-P HDD:Toshiba 1Tb 7200rpm PSU:Sentey650W

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8652801
Share on other sites

Link to post
Share on other sites

38 minutes ago, patrickjp93 said:

I'm confused as to what sort of assembly this even is, especially the goto which doesn't appear to have any well-defined conditions, but would cause an infinite loop if it didn't.

 

It looks like you're probably decrementing and overflowing down based on the loop logic.

The program shouldn't have an end, just the controller always receives the numbers thru portb, adds them and displays them through a 7degment display

Case: NZXT phantom CPU:I5-4460 GPU:MSI-GTX1070 Gaming X RAM:2x4Gb-DDR3-HyperX fury MOBO:Asus Z97-P HDD:Toshiba 1Tb 7200rpm PSU:Sentey650W

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8652808
Share on other sites

Link to post
Share on other sites

1 minute ago, gabrielcarvfer said:

Just saying, there are multiple assembly languages, one or more for each ISA.


In your case, as you're using PIC16f627a, you should be talking about its assembly, that you can find at the documentation provided by the manufacturer (page 118 from http://ww1.microchip.com/downloads/en/DeviceDoc/40044G.pdf).

 

If you're asking for help, please help people providing useful information about your problem =/

Ok sorry for that. Any idea on what the error could be?

Case: NZXT phantom CPU:I5-4460 GPU:MSI-GTX1070 Gaming X RAM:2x4Gb-DDR3-HyperX fury MOBO:Asus Z97-P HDD:Toshiba 1Tb 7200rpm PSU:Sentey650W

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8652873
Share on other sites

Link to post
Share on other sites

@Juanse

 

After calling the lookup table "tabla" the second time you move the value to PORTB in stead of PORTA

mostrar
	movf	unidad,w
	call	tabla
	movwf	PORTA
	bsf	PORTB,3
	call	delay
	bcf	PORTB,3
	movf	decena,w
	call	tabla
	movwf	PORTB   <====== MOVWF PORTA ?
	bsf	PORTB,7
	call	delay
	bcf	PORTB,7
	goto	principal

 

@gabrielcarvfer This is assembly for PIC16 micro-controllers. A small cheap (couple of dollars per chip) 8 bit micro-controller with a RISC instruction set that only has 35 instructions. You can't really compare it to a full blown CPU like x86.

 

"tabla" is a lookup table, it's how lookup tables are done on PIC16. You call the subroutine with a value in W, W being the one and only CPU register this chip has. "ADDWF PCL, F" at the top of the routine adds the value in W (+1) to the instruction pointer, jumping to the appropriate "retlw" instruction in the table - which returns the table value in W.

 

 

 

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8655387
Share on other sites

Link to post
Share on other sites

15 hours ago, patrickjp93 said:

I'm confused as to what sort of assembly this even is, especially the goto which doesn't appear to have any well-defined conditions, but would cause an infinite loop if it didn't.

 

It looks like you're probably decrementing and overflowing down based on the loop logic.

In PIC assembly, logic is determined by the instruction before the goto. Nearly all logic instructions skip the next instruction if a condition is met. For example "DECFSZ X"  DECreases a File (variable, X in this case) and Skips the next instruction if the result is Zero. So you get code like:

 

DECFSZ X
GOTO Result_nonzero
... ;continue code for result zero

 

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8655410
Share on other sites

Link to post
Share on other sites

20 hours ago, gabrielcarvfer said:

Just saying, there are multiple assembly languages, one or more for each ISA.


In your case, as you're using PIC16f627a, you should be talking about its assembly, that you can find at the documentation provided by the manufacturer (page 118 from http://ww1.microchip.com/downloads/en/DeviceDoc/40044G.pdf).

 

If you're asking for help, please help people providing useful information about your problem =/

@gabrielcarvfer@Unimportant@Pinguinsan@patrickjp93

I fixed it! I just retyped the "mostrar" routine all over again and it worked. I have no idea of what I did wrong, but hey! it worked!

Case: NZXT phantom CPU:I5-4460 GPU:MSI-GTX1070 Gaming X RAM:2x4Gb-DDR3-HyperX fury MOBO:Asus Z97-P HDD:Toshiba 1Tb 7200rpm PSU:Sentey650W

Link to comment
https://linustechtips.com/topic/671094-assembler-issues/#findComment-8656826
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×