Skip to main content
Added info about doing the same on Z80.
Source Link

Especially on the Z80 CPU you could use the same principle, since although a Z80 is a 8-bit CPU, it still supports 16-bit additions:

ADD HL, DE ADD HL, BC

Especially on the Z80 CPU you could use the same principle, since although a Z80 is a 8-bit CPU, it still supports 16-bit additions:

ADD HL, DE ADD HL, BC

Corrected a spelling error.
Source Link

Basically, it divides an unsigned BYTE by 3 by using "multiplyu"multiply by reciprocal" -principle.

Basically, it divides an unsigned BYTE by 3 by using "multiplyu by reciprocal" -principle.

Basically, it divides an unsigned BYTE by 3 by using "multiply by reciprocal" -principle.

Source Link

Consider the following x86 code (used as inline-assembly in Delphi code):

function DIVByteBy3Fast(B:Byte):WORD; asm xor AH, AH // Convert BYTE in AL -> WORD in AX. mov CX, AX // copy of B -> CX // call MulWordBy10 // AX := 10 * B mov DX, AX // MulWordBy10 - inlined here. add AX, AX add AX, AX add AX, DX add AX, AX mov DX, AX // DX := 10 * B //call MulWordBy16 // AX := 160 * B add AX, AX // MulWordBy16 - inlined here. add AX, AX add AX, AX add AX, AX ADD AX, DX // AX := 170 * B ADD AX, CX // AX := 171 * B SHR AX, 9 // AX := (171/512) * B = B DIV 3 end; 

Basically, it divides an unsigned BYTE by 3 by using "multiplyu by reciprocal" -principle.