⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basic_fn.asm

📁 calculator code ,use toshibaor nec LSI
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	f,equal_key9		;if jump status is 0 -> branch
		ld	hl,W1
		call	wk_round		;W1(calculated answer) rounding
		ld	(SYM),S_AST
		;V1.27-------------------------------
;V4.13		@BBC	(SW_SG,equal_key3)	;V2.07
;V4.13		ld	(SYM),S_PLS		;v2.07
equal_key3:
		ld	hl,W1		;V1.27
		call	wk_print		;W1(calculated answer) print
		call	feed_1
		call	w1_to_ten		;for display calculated answer(W1)
;V4.13		@SEB	(F_FNEABL)	;V1.09
;V4.13		@BBC	(SW_SG,equal_key9)	;V1.17
;V4.13		call	w1_to_w2		;V1.33
;V4.13		ld	hl,ACC			;V1.33
;V4.13		call	wk_update		;V1.33
;V4.13		@BBS	(F_CALER,equal_key9)	;V1.33
;V4.13		ld	hl,IC_A			;V1.33
;V4.13		call	ic_update		;V1.33
equal_key9:
		ld	(SYM),S_AST		;for error print
		j	function_end

equal_mup:
        test	(FLG_MODE).2
	j	t,equal_mup_x
		call	ten_to_w2dp	;V4.09
		jp	equal_mup_y	;v4.09
equal_mup_x:				;V4.09
		call	ten_to_w2		;tenkey -> W2(no DP adjustment)
equal_mup_y:				;V4.09
;V4.12		@SEB	(F_REVCAN)	;V4.09
		ld	(SYM),S_PRMU
		ld	hl,W2
		call	wk_print		;W2(input value) print
		call	w2_to_w1
	call	w2_clear
	ld	(W2_LSD-1),0x01		;set 100 to W2
		call	calc_div		;W1 <- MU%/100
		xor	(W1_S),0x01		;W1(MU%/100) sign change
	call	w2_clear
	ld	(W2_LSD),0x01		;set 1 to W2
		call	calc_add		;W1 <- 1 - (MU%/100)
		call	w1_to_w2
		call	const_to_w1
		call	calc_div		;W1 <- cost price / (1-margin/100)
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	f,equal_mup99		;if jump status is 0 -> branch
		call	w1_to_w4	;V1.17
		ld	hl,W1		;V1.09
		call	wk_round	;V1.09
		call	const_to_w2	;V1.32
		xor	(W2_S),1	;V1.32
		call	calc_add		;W1(difference) <- selling price - cost price
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	f,equal_mup9		;if jump status is 0 -> branch
		call	w1_to_w2		;W2 <- diffrence
		ld	hl,W1			;V1.09
		call	wk_round		;V1.09
equal_mup_1:					;V1.33
		ld	(SYM),S_DLAS		;
		call	wk_print		;defference print
		call	w4_to_w1		;V1.17
		ld	hl,W1
		call	wk_round		;
		ld	(SYM),S_AST		;
		call	wk_print		;selling price print
		ld	(FLG_C),0		;clear all constant caluculation flags
	ld	wa,C_MUP
	set	(C_MUP>>4).a
		ld	(FLG_E),0		;clear all caluculate instruction flags
		call	feed_1
		call	w1_to_ten		;
equal_mup9:
		ld	(SYM),S_AST		;for error print
		j	function_end
equal_mup99:
	ld	wa,F_ZDIVER
	set	(F_ZDIVER>>4).a
		ld	hl,W1			;V1.30
		call	_zerock			;V1.30
		j	ne,equal_mup9		;V1.30
		and	(W1_S),0		;V1.30
		j	equal_mup9
		;------------------------------------------------------------
equal_dlt:
        test	(FLG_MODE).2
	j	t,equal_dlt_x
		call	ten_to_w2dp		;V4.09
		jp	equal_dlt_y		;V4.09
equal_dlt_x:					;V4.09
		call	ten_to_w2		;tenkey -> W2(no DP adjustment)
equal_dlt_y:					;V4.09
;V4.12		@SEB	(F_REVCAN)		;V4.09
		ld	(SYM),S_EQU
		ld	hl,W2
		call	wk_print		
		call	const_to_w1
		call	exchg_w12	;V1.34
		xor	(W2_S),1	;V1.34
		call	calc_add
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	f,equal_dlt9		;if jump status is 0 -> branch
		ld	hl,W1		;
;V3.00		call	wk_round	;
;V3.00		@BBS	(M_VIC,equal_dlt_0)	;V2.06
;V3.00		ld	(SYM),S_DLTA
;V3.00		jp	equal_dlt_1			;V1.30
;V3.00equal_dlt_0:						;V1.30
		ld	(SYM),S_DLAS			;V1.30
equal_dlt_1:
		call	wk_print
		call	const_to_w2
	ld	wa,F_PERCAL
	set	(F_PERCAL>>4).a
		call	calc_div		;
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	f,equal_dlt99		;if jump status is 0 -> branch
		ld	hl,W1	
		call	_zerock
		j	ne,equal_dlt_1_0	;V1.34
		ld	(W1_S),0		;V1.34
equal_dlt_1_0:					;V1.34
		call	wk_round	
;V3.00		ld	(SYM),S_PER			;
;V3.00		@BBC	(M_VIC,equal_dlt_2)		;V2.06
		ld	(SYM),S_PRDL			;V1.30
equal_dlt_2:						;V1.30
		call	wk_print		;
		ld	(FLG_C),0		;
	ld	wa,C_DLT
	set	(C_DLT>>4).a
		ld	(FLG_E),0		;
		call	feed_1
		call	w1_to_ten		;
equal_dlt9:
		ld	(SYM),S_AST		;
		j	function_end
equal_dlt99:
		call	w1_clear
		j	equal_dlt9
		;-------------------------------------------------------------------
equal_sub:
	ld	wa,F_REVCAN
	set	(F_REVCAN>>4).a
;V1.32		ld	a,(TEN_CT)		;no tenkey?
;V1.32		j	nz,equal_s2		; with tenkey ->
	ld	wa,F_TNKEY
	test	(F_TNKEY>>4).a		;bit -reverse-> jump status
	j	f,equal_s2		;if jump status is 0 -> branch
;if no tenkey entry, check x,div,repeat entry........
		cmp	(PRE_KEY),K_MUL		;if previouse key is X ?
		j	eq,equal_s3		; yes -> use W2(previouse multiplicand value) for repeat entry
		cmp	(PRE_KEY),K_DIV		;if previouse key is div ?
		j	eq,equal_s3		; yes -> use W2(previouse dividend value) for repeat entry
equal_s2:
		cmp	(KEYIN),K_PER		;V1.28\for percent calculate, no need 'adm'
		j	eq,equal_s22		;V1.28/
;V4.13		@BBC	(SW_ADM12,equal_s22)	;V1.16
;V4.13		@BBS	(E_MUL,equal_s21)	;V1.16
;V4.13		@BBS	(C_MUL,equal_s21)	;V1.16

;V1.30		@BBS	(E_DIV,equal_s21)	;V1.30
;V4.13		@BBS	(C_DIV,equal_s21)	;V1.30

;V4.13		jp	equal_s22		;V1.16
equal_s21:					;V1.16
;V4.13		call	add_mode		;V1.16
;V4.13		j	cs,equal_s3		;V1.16
equal_s22:					;V1.16
        test	(FLG_MODE).2
	j	t,equal_s23
		call	ten_to_w2dp	;V4.09
		jp	equal_s24	;V4.09
equal_s23:				;V4.09
		call	ten_to_w2		;tenkey -> W2(no DP adjustment)
equal_s24:				;V4.09
equal_s3:
		ld	hl,W2
		ld	(SYM),S_EQU
		cmp	(KEYIN),K_PER		;% key?
		j	ne,equal_s4		; no -> 
		ld	(SYM),S_PER
	ld	wa,F_PERCAL
	set	(F_PERCAL>>4).a
equal_s4:
		call	wk_print		;W2(input value) print
		call	calc_sub		;calculation if Mul or Div flag is set before
		ld	a,(FLG_E)		;copy FLG_E to FLG_C for constant calculation
		j	z,equal_s6		;if no FLG_E flags(means constant calculation)  yes-> do not copy FLG_E -> FLG_C
		and	a,0y00000011		;E_MUL,E_DIV only
		ld	(FLG_C),a		;
		ld	(FLG_E),0		;clear all caluculate instruction flags
equal_s6:		
		ret

calc_sub:
	ld	wa,E_MUL
	test	(E_MUL>>4).a		;bit -reverse-> jump status
	j	f,calc_smul		;if jump status is 0 -> branch
	ld	wa,E_DIV
	test	(E_DIV>>4).a		;bit -reverse-> jump status
	j	f,calc_sdiv		;if jump status is 0 -> branch
	ld	wa,C_MUL
	test	(C_MUL>>4).a		;bit -reverse-> jump status
	j	f,calc_smul		;if jump status is 0 -> branch
	ld	wa,C_DIV
	test	(C_DIV>>4).a		;bit -reverse-> jump status
	j	f,calc_sdivc		;if jump status is 0 -> branch
		call	w2_to_w1		;if no Mu or Div instruction, set input value to calculated answer
		j	calc_sub9
calc_smul:
		call	const_to_w1
		call	calc_mult		;CONST x input value -> W1
		j	calc_sub9
calc_sdiv:
		call	const_to_w1
		call	calc_div		;CONST / input value -> W1
		call	w2_to_const		;input value save to CONST(for constant calculation)
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	t,calc_sdiv_1		;if jump status is 1 -> branch
	ld	wa,F_ZDIVER
	set	(F_ZDIVER>>4).a
calc_sdiv_1:					;V1.32
		j	calc_sub9
calc_sdivc:
		call	const_to_w1		;when constant division calculation, W2(input)is dividend and CONST is divider 
		call	exchg_w12		; W1(input value)  W2(CONST)
		call	calc_div		; input value / CONST -> W1(answer)
	ld	wa,F_CALER
	test	(F_CALER>>4).a		;bit -reverse-> jump status
	j	t,calc_sdivc_1		;if jump status is 1 -> branch
	ld	wa,F_ZDIVER
	set	(F_ZDIVER>>4).a
calc_sdivc_1:					;V1.32
calc_sub9:
	ld	wa,ERR_CLR
	clr	(ERR_CLR>>4).a
		ret
;===============================================================================
;square root
;===============================================================================
square_root:
	ld	wa,F_RATE
	test	(F_RATE>>4).a		;bit -reverse-> jump status
	j	f,no_operation		;if jump status is 0 -> branch
	call	w1_clear		;V4.12
	call	ten_to_w2dp
	call	w2_to_w4
	ld	(SYM),S_ROOT
	ld	wa,F_REVCAN
	set	(F_REVCAN>>4).a
	call	w2_print
	ld	wa,F_DOFF
	set	(F_DOFF>>4).a
	test	(W2_S).0
	j	t,square_root_0
	ld	wa,F_CALER
	set	(F_CALER>>4).a
	jp	square_root_99

square_root_0:
	ld	hl,W2
	call	_zerock
	j	z,square_root_90

	ld	d,13
	ld	c,0
	ld	hl,W2_MSD
square_root_1:
	ld	a,(hl+c)
	and	a,0xf0
	j	nz,square_root_2
	dec	d
	ld	a,(hl+c)
	and	a,0x0f
	j	nz,square_root_2
	dec	d
	inc	c
	jp	square_root_1

square_root_2:
	set	cf
	sub	d,(W2_DP)

	j	f,square_root_21
	ld	c,0
	set	cf
	sub	c,d
	ld	hl,root_tab_b
	jp	square_root_3
square_root_21:
	ld	hl,root_tab_a
	ld	c,d
square_root_3:
	shlc	c
	shlc	c
	shlc	c
	ld	d,7
	ld	ix,W2_MSD
square_root_22:
	ld	a,(hl+c)
	ld	(ix),a
	inc	c
	inc	ix
	dec	d
	j	f,square_root_22
	
	ld	e,15
square_root_4:
	call	ten_to_w1
	call	calc_div
	call	calc_add
	call	w2_clear
	ld	(W2_LSD),2
	call	calc_div
	call	exchg_w12
	call	w4_to_w1
	xor	(W1_S),1
	call	calc_add
	ld	hl,W1
	call	_zerock
	j	z,square_root_90
	call	w2_to_w4
	dec	e
	j	f,square_root_4	;V1.18 avoid 0.99999999998 no end cycle
square_root_90:
	call	com_w2_0p9999999999
	j	nz,square_root_91
	call	w2_clear
	ld	(W2_LSD),1
square_root_91:
	ld	(SYM),S_AST
	ld	hl,W2
	call	w2_round_print
	call	w2_to_ten
	call	feed_1
square_root_99:
;V4.17	ld	(FLG_E),0	
;V4.17	ld	(FLG_C),0		;V1.40
	ld	wa,F_DOFF
	clr	(F_DOFF>>4).a
	ld	(SYM),S_AST	;V4.12
	jp	function_end
;--------------------------------
com_w2_0p9999999999:
	call	w1_clear
		
	ld	wa,M14
	test	(M14>>4).a		;bit -reverse-> jump status
	j	t,com_w2_0p1		;if jump status is 1 -> branch
	ld	(W1_MSD),0x09
	ld	(W1_MSD+1),0x99
	ld	(W1_MSD+2),0x99
	jp	com_w2_0p3
com_w2_0p1:
	ld	wa,M10
	test	(M10>>4).a		;bit -reverse-> jump status
	j	f,com_w2_0p2		;if jump status is 0 -> branch
	ld	(W1_MSD+1),0x09
	ld	(W1_MSD+2),0x99
	jp	com_w2_0p3
com_w2_0p2:
	ld	(W1_MSD),0x00
	ld	(W1_MSD+1),0x00	
	ld	(W1_MSD+2),0x09	
com_w2_0p3:
	ld	(W1_MSD+3),0x99
	ld	(W1_MSD+4),0x99
	ld	(W1_MSD+5),0x99
	ld	(W1_MSD+6),0x99
	ld	(W1_DP),11
	ld	wa,M14
	test	(M14>>4).a		;bit -reverse-> jump status
	j	t,com_w2_0p4		;if jump status is 1 -> branch
	ld	(W1_DP),13
	jp	com_w2_0p5
com_w2_0p4:
	ld	wa,M10
	test	(M10>>4).a		;bit -reverse-> jump status
	j	t,com_w2_0p5		;if jump status is 1 -> branch
	ld	(W1_DP),9
com_w2_0p5:
	xor	(W1_S),1
	call	calc_add
	ld	wa,M14
	test	(M14>>4).a		;bit -reverse-> jump status
	j	f,com_w2_0p7		;if jump status is 0 -> branch
	ld	wa,M10
	test	(M10>>4).a		;bit -reverse-> jump status
	j	f,com_w2_0p8		;if jump status is 0 -> branch
com_w2_0p6:
	cmp	(W1_DP),11
	jp	com_w2_0p9
com_w2_0p7:
	cmp	(W1_DP),13
	jp	com_w2_0p9
com_w2_0p8:
	cmp	(W1_DP),9
com_w2_0p9:
	j	lt,com_w2_0pa
	and	(W1_LSD),0y11111110	;V1.30
com_w2_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -