Base 16 numbers needing a to f: Difference between revisions

no edit summary
(Added Sidef)
No edit summary
Line 36:
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
</pre>
=={{header|68000 Assembly}}==
<lang 68000devpac>MOVEQ #0,D0 ;clear D0
MOVEM.L D0,D1-D6 ;clear data regs
 
 
 
loop:
MOVE.W D0,D1 ;we'll use D1 as our temp storage.
JSR UnpackNibbles ;store each nibble in D2,D3,D4,D5 as separate values to ease comparison.
 
CMP.B #$0A,D2 ;compare to $0A
BCC dontPrintThis ;if less than, don't print D0 to the screen.
CMP.B #$0A,D3
bcc dontPrintThis ;repeat the comparison for each nibble.
CMP.B #$0A,D4
bcc dontPrintThis
CMP.B #$0A,D5
bcc dontPrintThis
 
JSR printD0
 
dontPrintThis: ;loop overhead time
ADDQ.W #1,D0
CMP.W #501,D0
BCC loop
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
forever:
JMP forever ;we are done, so trap the program counter to prevent a crash.
 
;;;;MAIN ENDS HERE
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SUBROUTINES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
UnpackNibbles:
;input: D1
MOVEM.W D1,D2-D5
AND.W #$F000,D2
LSR.W #8,D2
LSR.W #4,D2 ;right shift into bottom nibble
 
AND.W #$0F00,D3
LSR.W #8,D3
 
AND.W #$00F0,D4
LSR.W #4,D4
 
AND.W #$000F,D5
 
RTS
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printD0:
 
MOVE.W D0,D1
JSR UnpackNibbles
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CMP.B #$0A,D2 ;compare to $0A
BCC noCorrectHex2 ;the letters A-F are not next to 0-9 in ascii
ADD.B #$07,D2 ;in fact they are 7 characters away!
 
noCorrectHex2:
ADD.B #$30,D2 ;now D2 equals the ascii equivalent of its numeric value.
JSR PrintChar ;unimplemented hardware-dependent print routine.
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CMP.B #$0A,D3
BCC noCorrectHex3
ADD.B #$07,D3
noCorrectHex3:
 
ADD.B #$30,D3
JSR PrintChar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CMP.B #$0A,D4
BCC noCorrectHex4
ADD.B #$07,D4
noCorrectHex4:
 
ADD.B #$30,D4
JSR PrintChar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CMP.B #$0A,D5
BCC noCorrectHex5
ADD.B #$07,D5
noCorrectHex5:
 
ADD.B #$30,D5
JSR PrintChar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move.b #$20,d6 ;ascii for spacebar
jsr PrintChar ;unimplemented hardware-dependent print routine.
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</lang>
 
=={{header|ALGOL 68}}==
1,489

edits