Displaying an Integer

Fabii23 0 Tallied Votes 403 Views Share

An integer is loaded in from memory.
ran through two loops to determine the tens place and the ones place.
Integer is stored back to memory and displayed.

Example #98
Tens place -->9
Ones place -->8
:)

;Outputs an integer  loaded in from memory
.ORIG	x3000

LD	R5,NUM		;ASCII MASK
LEA	R4,TENS		; SPACE FOR 2 DIGITS

LD	R1,NUMBER	;NUMBER TO DISPLAY

	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TENPLACE
	ADD	R2,R2,#1	;INCREMENT COUNTER
	ADD	R1,R1,#-10	;ADD -10 TO NUMBER
				
BRP	TENPLACE		;IF POSITIVE LOOP UP

ADD	R2,R2,#-1
STR	R2,R4,#0

LDR	R0,R4,#0
ADD	R0,R0,R5

TRAP 	x21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AND	R2,R2,#0	;counter
LD	R1,NUMBER	;LOAD NUMBER BACK

ONEPLACE			;IF POSITIVE LOOP UP
	ADD	R1,R1,#-10	;ADD -10 TO NUMBER

BRP	ONEPLACE

ADD	R1,R1,#10	;GET POSITIVE NUMBER BACK	

STR	R1,R4,#1	;STORE IN ONES SPOT

LDR	R0,R4,#1
ADD	R0,R0,R5
TRAP 	x21

HALT


NUM	.FILL	x30
TENS	.blkw	2
NUMBER	.FILL	#98

MINUSTEN  	.FILL #-10             
TEN		.FILL #10  


.END