How to resolve the algorithm Character codes step by step in the 68000 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Character codes step by step in the 68000 Assembly programming language

Table of Contents

Problem Statement

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

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Character codes step by step in the 68000 Assembly programming language

Source code in the 68000 programming language

        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

  

You may also check:How to resolve the algorithm Loops/Foreach step by step in the Racket programming language
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the Maxima programming language
You may also check:How to resolve the algorithm Sub-unit squares step by step in the RPL programming language
You may also check:How to resolve the algorithm Text processing/Max licenses in use step by step in the Nim programming language
You may also check:How to resolve the algorithm Sudoku step by step in the Delphi programming language