N'th: Difference between revisions

1,717 bytes added ,  1 year ago
Line 36:
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th
</pre>
 
=={{header|68000 Assembly}}==
The function itself:
<lang 68000devpac>Nth:
MOVEQ #1,D1
.loop:
MOVE.L D1,-(SP)
MOVE.L D0,-(SP)
MOVE.B (2,SP),D0
JSR printhex
MOVE.B (3,SP),D0
JSR printhex
MOVE.L (SP)+,D0
MOVE.L D0,-(SP)
AND.W #$00FF,D0
;HANDLE SPECIAL CASES
CMP.B #$11,D0
BEQ .fourth
CMP.B #$12,D0
BEQ .fourth
CMP.B #$13,D0
BEQ .fourth
;HANDLE THE REST
AND.W #$000F,D0
CMP.B #1,D0
BEQ .first
CMP.B #2,D0
BEQ .second
CMP.B #3,D0
BEQ .third
.fourth:
LEA th,A3
bra .print
.third:
LEA rd,a3
bra .print
.second:
LEA nd,a3
bra .print
.first:
LEA est,a3
.print:
JSR PrintString
JSR newline
MOVE.L (SP)+,d0
MOVE.L (SP)+,d1
ABCD D1,D0
DBRA D7,.loop
rts
 
th:
dc.b "th",255
even
est:
dc.b "st",255
even
nd:
dc.b "nd",255
even
rd:
dc.b "rd",255
even</lang>
 
And the test cases (each was executed in separate builds of the Sega Genesis cartridge to have enough room to see them all at once)
<lang 68000devpac>MOVE.w #0,D0
MOVE.W #25,D7
JSR Nth
 
MOVE.w #$250,D0 ;since we're working with binary-coded decimal, this number is stored as hex.
MOVE.W #15,D7
JSR Nth
 
MOVE.w #$1000,D0 ;since we're working with binary-coded decimal, this number is stored as hex.
MOVE.W #25,D7
JSR Nth
 
jmp * ;stop the cpu - we're done.</lang>
 
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|8080 Assembly}}==
1,489

edits