func1.asm

来自「another 8051 core porocesssor vhdl sourc」· 汇编 代码 · 共 2,206 行 · 第 1/4 页

ASM
2,206
字号
	mov	a,#data0		;initialise a to 0	subb	a,#data0		;subtract 0	jnc	$ft017			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft017:	jnb	ac,$ft018		;no auxilliary carry	error	E_auxcarry_not_clear	;failed to clear aux carry;$ft018:	clr	c			;clear carry	clr	ac			;clear aux carry	clr	ov			;clear overflow	mov	a,#data0		;initialise a to 0	subb	a,#data80		;subtract 80h	jb	ov,$ft019		;overflow should be set	error	E_carry_not_clear		;failed to clear carry$ft019:	clr	c			;clear carry	subb	a,#data0		;subtract 0	jnb	ov,$ft020		;no overflow	error	E_ovflow_not_clear	;failed to clear overflow$ft020:	mov	a,#data80		;initialise a to 80h	setb	c			;set carry	subb	a,#data0		;subtract 0 and carry	jb	ov,$ft021		;overflow should be set	error	E_ovflow_not_set		;failed to set overflow$ft021:	clr	c			;clear carry	clr	ov			;clear overflow	mov	a,#data80		;initialise a to 80h	subb	a,#data7f		;subtract 7fh	jb	ov,$ft022		;overflow should be set	error	E_ovflow_not_set		;failed to set overflow$ft022:	subb	a,#data0		;subtract 0	jnb	ov,$ft023		;overflow should be cleared	error	E_ovflow_not_clear	;failed to clear overflow;$ft023:	setb	c			;set carry	setb	ov			;set overflow	mov	a,#datafb		;initialise a to fbh	mov	b,#data12		;initialise b to 12h	div	ab			;divide	jnc	$ft024			;carry should be cleared	error	E_carry_not_clear		;failed to clear overflow$ft024:	jnb	ov,$ft025		;overflow should be cleared	error	E_ovflow_not_clear	;failed to clear overflow$ft025:	setb	c			;set carry	mov	a,#data2		;initialise a to 2	mov	b,#data0		;initialise b to 0	div	ab			;divide	jnc	$ft026			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft026:	jb	ov,$ft027		;overflow should be set	error	E_ovflow_not_set		;failed to clear overflow;$ft027:	clr	c			;clear carry	clr	ov			;clear overflow	clr	ac			;clear aux carry	mov	a,#data1		;initialise a to 1	cjne	a,#data2,$ft028	nop$ft028:	jc	$ft029			;carry should be set	error	E_carry_not_set		;failed to set carry$ft029:	cjne	a,#data0,$ft030	nop$ft030:	jnc	$ft031			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft031:	mov	a,#data80		;initialise a to 80h	cjne	a,#dataff,$ft032	nop$ft032:	jc	$ft033	error	E_carry_not_set		;failed to set carry$ft033:	cjne	a,#data7f,$ft034	nop$ft034:	jnc	$ft035			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry;$ft035:	setb	c			;set carry	clr	ov			;clear overflow	mov	a,#data50		;initialise a to 50h	mov	b,#dataa0		;initialise b to a0h	mul	ab			;multiply	jnc	$ft036			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft036:	jb	ov,$ft037		;overflow should be set	error	E_ovflow_not_set		;failed to set overclow$ft037:	mov	a,#data2		;initialise a to 32h, b == 32h	mul	ab			;multiply	jnb	ov,$ft038		;overflow should be cleared	error	E_ovflow_not_clear	;failed to clear overflow;$ft038:	clr	c			;clear carry	clr	ac			;clear aux carry	clr	ov			;clear overflow	mov	a,#data30		;initialise a to 30h	add	a,#data99		;add 99h to a	da	a			;decimal adjust	jc	$ft039			;carry should be set	error	E_carry_not_set		;failed to clear carry$ft039:	mov	a,#data56		;initialise a to 56h	mov	r3,#data67		;initialise r3 to 67h	addc	a,r3			;add with previous carry	jnc	$ft040			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft040:	jnb	ac,$ft041		;aux carry should be clear	error	E_auxcarry_not_clear	;failed to clear aux carry$ft041:	da	a			;decimal adjust	jc	$ft042			;carry should be set	error	E_carry_not_set		;failed to set carry;$ft042:	clr	c			;clear carry	mov	a,#data80		;initialise a to 80h	rlc	a			;rotate left	jc	$ft043			;carry should be set	error	E_carry_not_set		;failed to set carry$ft043:	jz	$ft044			;a should be 0	error	E_zero_not_set		;failed to clear acc and set zero$ft044:	rlc	a			;rotate left again	jnc	$ft045			;carry should be cleared	error	E_carry_not_clear	;failed to clear carry$ft045:	cjne	a,#data1,$ft046		;a should equal 1	sjmp	$ft047$ft046:	error	E_zero_not_clear	;failed to clear acc and zero;$ft047:	clr	c			;clear carry	mov	a,#data1		;initialise a to 1	rrc	a			;rotate right	jc	$ft048			;carry should be set	error	E_carry_not_set		;failed to set carry$ft048:	jz	$ft049			;a should equal 0	error	E_zero_not_set		;failed to clear acc and set zero$ft049:	rrc	a			;rotate right again	jnc	$ft050			;carry should be cleared	error	E_carry_not_clear		;failed to clear carry$ft050:	cjne	a,#data80,$ft051    ;a should equal 80h	sjmp	addtest$ft051:	error	E_zero_not_clear	;failed to clear acc and zero;;============;ARITH-add test;============;=======addtest:;=======;; test add instructions	mov     a, #01h	mov     r5, #02h                ; initialise a and r5	add     a, r5                   ; add	cjne    a, #03h, add_er         ; check if we have 3	mov     b, #80h 	mov     a, #02h                 ; initialise a and b	add     a, b                    ; add	cjne    a, #82h, add_er	mov     r1, #6fh                ; get pointer to 6fh	mov     @r1, #02h               ; initialise value at 6fh	mov     a, #34h                 ; initialise a	add     a, @r1                  ; add	cjne    a, #36h, add_er	mov     a, #f0h                 ; initialise a	add     a, #02h                 ; add data2 to a	cjne    a, #f2h, add_er	sjmp    addctestadd_er: sjmp    add_er                  ; failed to add;============;ARITH-addc test;============;========addctest:;========;; test add carry instructions;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;;	mov     a, #01h                 ; initialise accumulator	mov     r3, #ffh                ; initialise register 3	mov	23h, #34h		; initialise address 23h	mov     psw, #0                 ; make sure carry flag is clear	addc    a, r3                   ; add r3 and carry flag to acc 	jz      adc00                   ; test for result of zero in acc	error   E_addc_zeronotset       ; failed if not zeroadc00:  jc      adc04                   ; test the carry flag	error   E_addc_carrynotset      ; failed if carry flag not set	cpl	D7h			; set the carry flag 	addc	a, 23h			; add contents of 23h and carry	jc	adc05			; carry flag should be reset	xrl	a, #35h			; test acc for correct result	jnz	adc05			; go to an error loop on failureadc04:  clr	c			: clear carry flag	mov     r1, #6fh                ; set pointer to 6fh	mov     @r1, #34h               ; initialise value at 6fh to 34h	mov     a, #34h                 ; initialise acc to 34h	addc    a, @r1                  ; add @r1 and carry flag to acc	cjne    a, #68h, adc05          ; check if result = 68h	sjmp    subbtest		; pass on to the next testadc05:  error   E_addc_acc_indirect     ; failed to add indirect loop;;;============;ARITH-subb test;============;========subbtest:;========;; test subtract instructions;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;;	mov     a, #02h                 ;initialise a to 2	mov     r2, #01h                ;initialise r2 to 1	setb    c                       ;set carry	subb    a, r2                   ;subtract	jz      sbb1                    ;a should equal 0	error   E_subb_acc_reg          ;failed to subtract reg from acc;sbb1:   mov     a, #7fh                 ;initialise a to 7fh	mov     b, #02h                 ;initialise b to 2	clr     c                       ;clear carry	subb    a, b                    ;subtract	cjne    a,#7dh, sbb2	sjmp    inctestsbb2:   error   E_subb_a_breg           ;failed to subtract a from b;;============;ARITH-inc test;============;=======inctest:;=======;; test increment instructions;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;;	clr     a                       ; clear accumulator	setb	c			; set carry flag	inc     a                       ; increment accumulator	jnc	inc_er			; carry should remain unaffected	cjne    a, #01h, inc_er		; result in accumulator is one	orl	a, #FFh			; set accumulator to FFh	inc	E0h			; increment accumulator	jnz	inc_er			; accumulator result is zero	mov	r5, #ACh		; load register five	mov	r0, #04h		; load register zero	inc	r0			; increment r0 to point to r5	inc	@r0			; increment r5 using r0  	mov	a, r5			; load accumulator with r5	xrl	a, #ADh			; XOR with correct result	jnz	inc_er			; accumulator should be zero	clr	c			; clear carry flag	mov     dpl, #ffh               ; initialise DPTR to FFh	mov     dph, #ffh	inc     dptr                    ; increment DPTR	jc	inc_er			; carry should remian unaffected	mov     a, dpl                  ; copy DPTR low byte to acc	cjne    a, #0, inc_er	mov     a, dph                  ; copy DPTR high byte to acc	cjne    a, #0, inc_er	sjmp    dectest			; pass on to the next testinc_er: sjmp    inc_er                  ; failed to increment error loop;=======dectest:;=======;; test decrement instructions;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;;	clr     a                       ; clear accumulator	dec     a                       ; decrement accumulator	cjne    a, #ffh, dec_er         ; compare with FFh	mov     r7, #0                  ; initialise register 7 to zero	dec     r7                      ; decrement register 7	cjne    r7, #ffh, dec_er        ; compare with FFh	mov	b, #89h			; load register B with 89h	dec	b			; decrement register B	mov	a, #88h			; load acc with expected result	cjne	a, b, dec_er		; test for the correct result	mov     r1, #20h                ; set pointer register to 20h	mov     @r1, #0                 ; initialise address 20h to zero	dec     @r1                     ; decrement contents of @r1	mov     a, @r1                  ; copy result to accumulator	cjne    a, #ffh, dec_er		; test for the correct result	sjmp    multest			; pass on to next testdec_er: sjmp    dec_er                  ; failed to decrement error loop;;ARITH-multiply test;=======multest:;=======;; test mul instructions; multiply to make 16 bit number; and check that the right values are in each register;	setb    c                       ; set carry	clr     ov                      ; clear overflow (OV) flag	mov     a, #50h                 ; initialise a to 50h	mov     b, #a0h                 ; initialise b to a0h	mul     ab                      ; multiply	jc      mul_jp                  ; carry should clear unconditionally	jb      ov, mul1                ; overflow should set	sjmp    mul_jpmul1:   jnz     mul_jp                  ; a should be zero (low byte of 3200h)	mov     a, #32h                 ; initialise a to 32h	cjne    a, b, mul_jp            ; b should be 32h (high byte of result)	setb    c	setb    ov                      ; set overflow flag	mov     a, #0ah	mov     b, #0bh                 ; set up new multiplicands	mul     ab                      ; multiply	jc      mul_jp                  ; carry should clear unconditionally	jb      ov, mul_jp              ; overflow flag should be clear	cjne    a, #6eh, mul_jp         ; expected result of 0ah x 0bh	mov     a, b                    ; load upper byte of result into acc.	jz      mul2                    ; should be zeromul_jp: ljmp    mul_er                  ; Intermediate hop to error handlermul2:   setb    c                       ; set carry flag	setb    ov                      ; set overflow flag	mov     b,#2Bh	mov     a,#3                    ; set new multiplicands	mul     ab                      ; multiply	jc      mul_er                  ; carry flag should be clear	jb      ov, mul_er              ; overflow flag should be clear	cjne    a, #81h, mul_er         ; expected result of 2Bh x 3	mov     a, b                    ; load upper byte of result into acc.	jnz     mul_er                  ; should be zero	sjmp	divtestmul_er: sjmp    mul_er                  ; multiply fail loop;;============;ARITH-divide test;============;========divtest:;========;; test division instructions;	setb    c                       ; set carry	setb    ov                      ; set overflow (OV) flag	mov     a, #fbh                 ; initialise a to fbh	mov     b, #12h                 ; initialise b to 12h	div     ab                      ; divide	cjne    a, #0dh, div_er         ; compare a to 13 (0dh)	mov     a, b                    ; mov b to a	cjne    a, #11h, div_er         ; compare to 11h, expected remainder	jc      div_er                  ; carry should clear unconditionally	jb      ov, div_er              ; overflow should clear	cpl     c                       ; set carry	clr     ov                      ; clear overflow flag	mov     b, #0                   ; special divisor condition	div     ab                      ; divide will only define the OV flag	jc      div_er                  ; carry should clear	jb      ov, daatest             ; overflow flag set for zero divisordiv_er: sjmp    div_er                  ; failed division. ;============;ARITH-decimal adjust accumulator;============;=======daatest:;=======;; test daa instructions; calculate 56h + 67h + 1 (i.e BCD 56 + BCD 67 + 1) = BCD 124	mov     a, #56h                 ; initialise a to 56h	mov     r3, #67h                ; initialise r3 to 67h	setb    c                       ; set carry	addc    a, r3                   ; add	da      a                       ; decimal adjust result	jb      ac, daa_er              ; auxillary carry should not change	jnc     daa_er                  ; carry bit should now be set	cjne    a, #24h, daa_er         ; compare result with 24h; calculate 30h + 99h = BCD 129	clr     c                       	mov     a,#data30               ; initialise a to 30h	add     a,#data99               ; add 99h to a	da      a                       ; decimal adjust result	jb      ac, daa_er              ; auxillary carry should not change	jnc     daa_er                  ; carry bit should now be set	cjne    a, #29h, daa_er         ; compare to 29h	sjmp    miscmov			; pass on to the next testdaa_er: sjmp    daa_er                  ; failed DAA error loop; Miscellaneous internal move instruction tests;=======miscmov:;=======	mov	r1, #7Fh		; initialise indirect pointer	mov	23h, #08h		; initialise data memory store	mov	24h, #10h		; initialise data memory store	mov	70h, #00h		; initialise data memory store	mov	7fh, #20h		; initialise data memory store	mov	70h, @r1		; indirect to direct memory move	mov	@r1, 23h		; direct to indirect memory move	mov	23h, 24h		; direct to direct memory move	mov	24h, r1			; register to direct memory move	mov	a, 70h			; recover data from @r1 (20h)	cjne	a, #20h, movfail	; go to error loop if incorrect	mov	a, 7Fh			; recover data from 23h	cjne	a, #08h, movfail	; go to error loop if incorrect	mov	a, 23h			; recover data from 24h	cjne	a, #10h, movfail	; go to error loop if incorrect	mov	a, 24h			; recover data from r1 (7Fh)	cjne	a, #7Fh, movfail	; go to error loop if incorrect	sjmp    movc_test		; pass on to next testmovfail:	sjmp	movfail			; miscellaneous moves error loop;; MOVX and MOVC tests;;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;;;=========movc_test:;=========	mov     a, #data2		; initialise accumulator with 2        add     a, #data2        	; account for sjmp code offset        movc    a, @a+pc         	; get byte from in-line table        sjmp    $mvc1;; MOVC program memory in-line data table;$mvc0:  db      dataff         		; initialise to ffh        db      data55         		; initialise to 55h        db      dataaa         		; initialise to aah        db      data7f         		; initialise to 7fh;$mvc1:  cjne    a, #dataaa, $mvc2        sjmp    $mvc3$mvc2:  error   E_movc_acc_pc		; failed to read table correctly$mvc3:  mov     dptr, #$mvc0		; point to external program data        mov     a, #data2+data1		; initialise acc to 3        movc    a, @a+dptr		; get program memory constant        cjne    a, #data7f, $mvc4	; which should equal 7fh        sjmp    movxtest$mvc4:  error   E_movc_acc_dataptr	; failed to read table correctly;;========movxtest:;========;; test move external instructions;; entry: no conditions;  exit: flags, a corrupt;        all other registers corrupt;        mov     r1, #ext2e       	; set pointer to external 2eh        clr     a               	; clear accumulator        movx    @r1, a           	; initialise external data to 0        inc     r1              	; step to next address 	inc	a        movx    @r1, a           	; clear external data memory        mov     r0, #ext2e       	; get pointer to external 2eh        mov     a, #dataff      	; initialise acc to ffh        movx    a, @r0           	; read value (should be 0)        jz      $mvx2$mvx1:  error   E_movx_acc_indirect	; failed to move external data $mvx2:  inc     r0        movx    a, @r0        cjne    a, #01h, $mvx3	sjmp	$mvx4$mvx3:	error   E_movx_acc_indirect	; failed to move external data$mvx4:	mov     dptr, #ext_data  	; initialise DPTR         mov     a, #dataaa       	; initialise acc to aah        movx    @dptr, a         	; store AAh in external byte 1        cpl     a               	; change acc to 55h        inc     dptr            	; step address        movx    @dptr, a         	; store in external byte 2        mov     dptr, #ext_data  	; re-initialise DPTR        clr     a               	; clear accumulator        movx    a, @dptr         	; get first external data byte        cjne    a, #dataaa, $mvx5        sjmp    $mvx6

⌨️ 快捷键说明

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