longx_tobcd added
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \ | ||||
| 	 sevenseg_dec.c sevenseg_dec_inv.c \ | ||||
| 	 int_to_bcd.c getbutton.c \ | ||||
| 	 getpin.c setpin_lo.c setpin_hi.c setpin.c getport.c \ | ||||
| 	 long_xadd.c long_xsub.c long_xset.c long_xrlc.c long_xdiv.c long_xcpy.c | ||||
| 	 long_xadd.c long_xsub.c long_xset.c long_xrlc.c long_xdiv.c long_xcpy.c long_xtobcd.c | ||||
|  | ||||
| LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) | ||||
| LIBNAME=mc8051fun.lib | ||||
|  | ||||
							
								
								
									
										88
									
								
								long_xtobcd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								long_xtobcd.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,88 @@ | ||||
|  | ||||
| /* | ||||
| r0 = bin | ||||
| r1 = bcd | ||||
| r7 = len of bin | ||||
| r6 = len of bcd | ||||
| */ | ||||
|  | ||||
| #include "mc8051fun.h" | ||||
|  | ||||
| // double dabble | ||||
|  | ||||
| void long_xtobcd() __naked | ||||
| { | ||||
| 	__asm | ||||
| .globl long_xtobcd | ||||
| 	 | ||||
| long_xtobcd: | ||||
|  | ||||
| 	; fill dst with zeroes | ||||
|  | ||||
| 	mov	r3,AR1		; save r1 in r3 | ||||
| 	mov	r4,AR6		; use r4 as counter | ||||
| 	mov	a,#0x00 | ||||
|  | ||||
| 000$: | ||||
| 	movx	@r1,a | ||||
| 	inc	r1 | ||||
| 	djnz	r4,000$ | ||||
|  | ||||
| 	mov	a,r0 | ||||
| 	add	a,r7 | ||||
| 	dec	a | ||||
| 	mov	r0,a | ||||
| 	mov	r2,AR0		; save r0 in r2	 | ||||
|  | ||||
| 006$:	 | ||||
| 	movx 	a,@r0 | ||||
| 	mov	r5,#0x08 | ||||
| 005$: | ||||
| 	mov	r4,AR6		; use r4 as counter | ||||
| 	mov	r1,AR3 | ||||
|  | ||||
| 	push 	ACC | ||||
| 004$: | ||||
| 	movx	a,@r1 | ||||
| 	acall	003$ | ||||
| 	acall	003$ | ||||
| 	movx	@r1,a | ||||
| 	inc	r1 | ||||
| 	djnz	r4,004$ | ||||
|  | ||||
| 	pop	ACC | ||||
|  | ||||
|  | ||||
| 	rlc	a | ||||
| 	push 	ACC | ||||
| 	push	AR0 | ||||
| 	push	AR7 | ||||
| 	mov	r7,AR6 | ||||
| 	mov	r0,AR3 | ||||
| 	lcall	long_xrlc | ||||
| 	pop 	AR7 | ||||
| 	pop	AR0 | ||||
| 	pop	ACC | ||||
| 	djnz	r5,005$ | ||||
|  | ||||
|  | ||||
| 	dec	r0 | ||||
| 	djnz	r7,006$ | ||||
| 	ret | ||||
| 	 | ||||
|  | ||||
| 003$: | ||||
| 	swap	a | ||||
| 	clr	c | ||||
| 	subb	a,#0x50 | ||||
| 	jc	002$ | ||||
| 	add	a,#0x30 | ||||
| 002$: | ||||
| 	add	a,#0x50 | ||||
| 	ret | ||||
| 	 | ||||
| __endasm; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user