

Task

Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses).



Example

The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode).

Conversely, given a code, print out the corresponding character.




        JSR ResetCoords					;RESET TYPING CURSOR
 
	MOVE.B #'A',D1
	MOVE.W #25,D2
	MOVE.B #0,(softCarriageReturn) ;new line takes the cursor to left edge of screen.
	jsr PrintAllTheCodes
 
	jsr ResetCoords
	MOVE.B #8,(Cursor_X)
	MOVE.B #'a',D1
	MOVE.W #25,D2
	MOVE.B #8,(softCarriageReturn) 
	;set the writing cursor to column 3 of the screen
	;so we don't erase the old output.
 
 
	jsr PrintAllTheCodes
 
 
forever:
	bra forever
 
 
 
PrintAllTheCodes:
	MOVE.B D1,D0
	jsr PrintChar			;print the character as-is
 
	MOVE.B #" ",D0
	jsr PrintChar
	MOVE.B #"=",D0
	jsr PrintChar
	MOVE.B #" ",D0
	jsr PrintChar
 
	MOVE.B D1,D0			;get ready to print the code
 
	JSR UnpackNibbles8
	SWAP D0
	ADD.B #$30,D0
	JSR PrintChar
 
	SWAP D0
	CMP.B #10,D0
	BCS noCorrectHex
	ADD.B #$07,D0
noCorrectHex:
	ADD.B #$30,D0
	JSR PrintChar
 
	MOVE.B (softCarriageReturn),D0
	JSR doNewLine2				;new line, with D0 as the carraige return point.
 
	ADDQ.B #1,D1
	DBRA D2,PrintAllTheCodes
	rts
 
 
UnpackNibbles8:
; INPUT: D0 = THE VALUE YOU WISH TO UNPACK.
; HIGH NIBBLE IN HIGH WORD OF D0, LOW NIBBLE IN LOW WORD. SWAP D0 TO GET THE OTHER HALF.
	pushWord D1
		CLR.W D1		
		MOVE.B D0,D1
		CLR.L D0
		MOVE.B D1,D0	 ;now D0 = D1 = $000000II, where I = input
 
		AND.B #$F0,D0	 ;chop off bottom nibble
		LSR.B #4,D0		 ;downshift top nibble into bottom nibble of the word
		SWAP D0			 ;store in high word
		AND.B #$0F,D1	 ;chop off bottom nibble
		MOVE.B D1,D0	 ;store in low word
	popWord D1
	rts