I wrote these subroutines while learning how to program on the MiniMax8085 board -- a simple 8085-based single board computer (SBC). My board's RAM starts at 0x8000, so that's where the subroutines are. You should update the addresses and jump instructions based on your RAM size (E.G. if it has 8K of RAM, start at 0xE000). To load the subroutines on MON85, use i ADDR (ADDR is the address of the start) and then paste in the Intel hex (listed after the assembly).
Input:
C - Character to print
Output:
Character printed to the USART
8200Â Â DB 09Â Â Â Â IN Â 09
8202Â Â E6 01Â Â Â Â ANIÂ 01
8204Â Â CA 00 82 Â Â JZ Â 8200
8207Â Â 79 Â Â Â Â Â MOVÂ A,C
8208Â Â D3 08Â Â Â Â OUTÂ 08
820AÂ Â C9 Â Â Â Â Â RET
:0C820000DB09E601CA008279D308C9003E
:00000001FF
Input:
HL - Address of the text string to print
Output:
String printed to the USART
8100Â Â 3E 00 Â Â Â MVIÂ A 00
8102Â Â 4EÂ Â Â Â Â MOVÂ C,M
8103Â Â B9Â Â Â Â Â CMPÂ C
8104Â Â CA 0E 81Â Â JZ Â 810E
8107Â Â 23Â Â Â Â Â INXÂ H
8108Â Â CD 00 82Â Â CALL 8200
810BÂ Â C3 00 81Â Â JMPÂ 8100
810EÂ Â C9Â Â Â Â Â RET
:108100003E004EB9CA0E8123CD0082C30081C90052
:00000001FF
Input:
none
Output:
A - Character from the USART
8180Â Â D8 09 Â Â Â INÂ 09
8182Â Â E6 02 Â Â Â ANI 02
8184Â Â CA 80 81Â Â JSÂ 8180
8187Â Â D8 08 Â Â Â INÂ 08
8189Â Â C9Â Â Â Â Â RET
:108100003E004EB9CA0E8123CD0082C30081C90052
:00000001FF
Input:
C - Byte to print
Output:
Byte printed to the USART
8280Â Â F5 Â Â Â Â Â PUSH PSWÂ Â ; Push acc. and flags
8281Â Â 79 Â Â Â Â Â MOVÂ A,CÂ Â ; Copy input into acc.
8282Â Â E6 0FÂ Â Â Â ANIÂ 0F Â Â ; Get lower half of acc.
8284Â Â C6 30Â Â Â Â ADIÂ 30 Â Â ; Add 0x30 (ascii '0') to acc.
8286Â Â FE 39Â Â Â Â CPIÂ 3A Â Â ; See if acc. is greater than 9 (characters after digits are ":;<=>?")
8288Â Â DA 8D 82 Â Â JC Â 828E Â ; Acc. is not a hex number, so skip adding
828BÂ Â C6 07Â Â Â Â ADIÂ 07 Â Â ; Add 0x07 to get to capital letters (use 0x27 if you want lower case)
828DÂ Â 47 Â Â Â Â Â MOVÂ B,AÂ Â ; Move character into B to be later moved into C for printing
828EÂ Â 79 Â Â Â Â Â MOVÂ A,CÂ Â ; See 8281
828FÂ Â E6 F0Â Â Â Â ANIÂ F0 Â Â ; See 8282
8291Â Â 07 Â Â Â Â Â RLC Â Â Â Â ; Shift
8292Â Â 07 Â Â Â Â Â RLC Â Â Â Â ; Acc.
8293Â Â 07 Â Â Â Â Â RLC Â Â Â Â ; Four
8294Â Â 07 Â Â Â Â Â RLC Â Â Â Â ; Bits
8295Â Â C6 30Â Â Â Â ADIÂ 30 Â Â ; See 8284
8297Â Â FE 39Â Â Â Â CPIÂ 3A Â Â ; See 8286
8299Â Â DA 9E 82 Â Â JC Â 829F Â ; See 8288
829CÂ Â C6 07Â Â Â Â ADIÂ 07 Â Â ; See 828B
829EÂ Â 4F Â Â Â Â Â MOVÂ C,AÂ Â ; Move character into C to be printed first
829FÂ Â F1 Â Â Â Â Â POPÂ PSWÂ Â ; Pop acc. and flags
82A0Â Â C9 Â Â Â Â Â RET Â Â Â Â ; Exit
Lets use an example: 0x7F (01111111)
Get the lower 4-bits (nibble) of the input: 0x0F
Add 0x30 - the ASCII code of "0": 0x3F
If the result value is greater than 0x39:
Add 0x07, so that the values from 0xA to 0xF are translated to the ASCII codes of "A" to "F": 0x46
Store the result value (ASCII code) into B
Get the higher 4-bits (nibble) of the input: 0x70
Shift the value left 4 times: 0x07
Add 0x30 - the ASCI code of "0": 0x37
If the result is value greater than 0x39:
No
Store the result value (ASCII code) into C
Return
:10828000F579E60FC630FE3ADA8D82C6074779E601
:10829000F007070707C630FE3ADA9E82C6074FF19D
:0182A000C914
:00000001FF
Input:
B,C - Factors
Output:
HL - product
8300Â Â F5 Â Â Â Â PUSH PSW
8301Â Â C5 Â Â Â Â PUSH B
8302Â Â D5 Â Â Â Â PUSH D
8303Â Â 26 00Â Â Â MVIÂ H,$00
8305Â Â 6C Â Â Â Â MOVÂ L,H
8306Â Â 54 Â Â Â Â MOVÂ D,H
8307Â Â 59 Â Â Â Â MOVÂ E,C
8308Â Â 78 Â Â Â Â MOVÂ A,B
8309Â Â 37 Â Â Â Â STC
830AÂ Â 3F Â Â Â Â CMC
830BÂ Â 1F Â Â Â Â RAR
830CÂ Â 47 Â Â Â Â MOVÂ B,A
830DÂ Â D2 11 83 Â JNCÂ $8311
8310Â Â 19 Â Â Â Â DADÂ D
8311Â Â 37 Â Â Â Â STC
8312Â Â 3F Â Â Â Â CMC
8313Â Â 7B Â Â Â Â MOVÂ A,E
8314Â Â 17 Â Â Â Â RAL
8315Â Â 5F Â Â Â Â MOVÂ E,A
8316Â Â 7A Â Â Â Â MOVÂ A,D
8317Â Â 17 Â Â Â Â RAL
8318Â Â 57 Â Â Â Â MOVÂ D,A
8319Â Â 3E 00Â Â Â MVIÂ A,$00
831BÂ Â B8 Â Â Â Â CMPÂ B
831CÂ Â C2 08 83 Â JNZÂ $8308
831FÂ Â D1 Â Â Â Â POPÂ D
8320Â Â C1 Â Â Â Â POPÂ B
8321Â Â F1 Â Â Â Â POPÂ PSW
8322Â Â C9 Â Â Â Â RET
Lets use the example of B: 0x06 (00000110) times C: 0x0B (00001011)
Start with a standard multiplication layout but in binary:
  00001011
x 00000110
----------
Expand the top value (stored in register C) to a 16 bit value (stored in register pair DE), and zero the output value (register pair HL):
  0000000000001011
x     00000110
------------------
  0000000000000000
In a loop:
Shift the bottom value (register B) to the right through carry:
  0000000000001011
x     00000011 Carry = 0
------------------
  0000000000000000
If the carry flag is set, add the top value (register pair DE) to the output (register pair HL) and reset the carry flag
Shift the top value (register pair DE) to the left;
  0000000000010110
x     00000011 Carry = 0
------------------
  0000000000000000
If the bottom value is not zero, repeat the loop:
  0000000000010110
x     00000001 Carry = 1
------------------
  0000000000010110
  0000000000101100
x     00000001 Carry = 0
------------------
  0000000000010110
  0000000000101100
x     00000000 Carry = 1
------------------
  0000000000010110
  0000000001011000
x     00000000 Carry = 0
------------------
           1111
  0000000000101100
+ 0000000000010110
------------------
  0000000001000010
Now that the bottom value is zero, the loop stops and subroutine returns the value of 0x42 (0000000001000010) in register pair HL
Now lets see how the subroutine works with the factors C = 0x1B (00011011) x B = 0x97 (10010111)
  0000000000011011
x     10010111
------------------
  0000000000000000
  0000000000011011
x     01001011 Carry = 1
------------------
  0000000000000000
  0000000000110110
x     01001011 Carry = 0
------------------
  0000000000011011
  0000000000110110
x     00100101 Carry = 1
------------------
  0000000000011011
  0000000001101100
x     00100101 Carry = 0
------------------
           11111
  0000000000110110
+ 0000000000011011
------------------
  0000000001010001
  0000000001101100
x     00010010 Carry = 1
------------------
  0000000001010001
  0000000011011000
x     00010010 Carry = 0
------------------
          1
  0000000001101100
+ 0000000001010001
------------------
  0000000010111101
  0000000011011000
x     0001001 Carry = 0
------------------
  0000000010111101
  0000000110110000
x     0001001 Carry = 0
------------------
  0000000010111101
  0000000110110000
x     0000100 Carry = 1
------------------
  0000000010111101
  0000001101100000
x     00000100 Carry = 0
------------------
        11 11
  0000000110110000
+ 0000000010111101
------------------
  0000001001101101
  0000001101100000
x     00000010 Carry = 0
------------------
  0000001001101101
  0000011011000000
x     00000010 Carry = 0
------------------
  0000001001101101
  0000011011000000
x     00000001 Carry = 0
------------------
  0000001001101101
  0000110110000000
x     00000001 Carry = 0
------------------
  0000001001101101
  0000110110000000
x     00000000 Carry = 1
------------------
  0000001001101101
  0001101100000000
x     00000000 Carry = 0
------------------
  0000110110000000
+ 0000001001101101
------------------
  0000111111101101
The subroutine exits with an answer of 0x0FED (0000111111101101) in register pair HL
:10830000F5C5D526006C545978373F1F47D2118329
:1083100019373F7B175F7A17573E00B8C20883D125
:03832000C1F1C981
:00000001FF