; bcd_sub.asm
; subtract two 4bit numbers on the Intel 4004
; bcd-wise
 FIM R0R1, 0x42 ; initialize R0=2 & R1=4
 FIM R2R3, 0    ; clear result pair
 LD R0          ; load R0 into accumulator
 SUB R1         ; subtract second number
 XCH R1         ; and store in R1
 JCN C, end     ; carry not set when result<0
 LD R1          ; load result into accumulator
 CMA            ; build complement of accu
 CLC            ; clear carry
 IAC            ; increment accu (=> 2-complement)
 XCH R1         ; right result back to R1
 STC            ; set carry to show borrow
done:
 JUN done       ; end 