Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link
edited body
Source Link
640KB
  • 12.4k
  • 2
  • 38
  • 61

#Intel 8080 Machine Codemachine code, Altair 8800, 22 bytes

0000 0e 02 11 16 00 21 18 00 af 1a 8e 12 0d ca 15 00 
0010 13 23 c3 09 00 76 0d0e 00 0e0f 00

#Intel 8080 Machine Code, Altair 8800, 22 bytes

0000 0e 02 11 16 00 21 18 00 af 1a 8e 12 0d ca 15 00 
0010 13 23 c3 09 00 76 0d 00 0e 00

#Intel 8080 machine code, Altair 8800, 22 bytes

0000 0e 02 11 16 00 21 18 00 af 1a 8e 12 0d ca 15 00 
0010 13 23 c3 09 00 76 0e 00 0f 00
added 18 characters in body
Source Link
640KB
  • 12.4k
  • 2
  • 38
  • 61

This will add two integers of nearly any size (16, 32, 64-bit, etc) using an Intel 8080 , 8-bit CPU (c. 1974). This is implemented as a full program, running on a MITS Altair 8800.

Step Switches 0-7 Control Switch Instruction Comment
1 RESET
2 00 001 110 DEPOSIT MVI C, 2 ; loop counter set to word size
3 00 000 010 DEPOSIT NEXT ; value is 2
4 00 010 001 " LXI D, 16H ; load address of first term into E:D
5 00 010 110 " ; at memory address 16H
6 00 000 000 " 
7 00 100 001 " LXI H, 18H ; load address of second term into H:L
8 00 011 000 " ; memory address 16H + word size = 18H
9 00 000 000 " 
10 10 101 111 " XRA A ; clear accumulator
11 00 011 010 " LOOP:LDAX D ; load [E:D] into A
12 10 001 110 " ADC M ; add [H:L] + previous carry, to A
13 00 010 010 " STAX D ; store result in A to [E:D]
14 00 001 101 " DCR C ; decrement loop counter
15 11 001 010 " JZ DONE ; if counter is zero, end addition
16 00 010 101 " ; jump to step 23
17 00 000 000 " 
18 00 010 011 " INX D ; first term next byte
19 00 100 011 " INX H ; second term next byte
20 11 000 011 " JMP LOOP ; restart loop
21 00 001 001 " ; jump to step 11
22 00 000 000 " 
23 01 110 110 " DONE:HLT ; halt CPU
24 00 001 110 " ; Term 1 low byte (14) 
25 00 000 000 " ; Term 1 high byte (0)
26 00 001 111 " ; Term 2 low byte (15) 
27 00 000 000 " ; Term 2 high byte (0) 
31 RESET ; Reset program counter to beginning
32 RUN
33 STOP 
34 00 010 110 EXAMINE ; low byte of output displayed on D7-D0
35 EXAMINE NEXT ; high byte of output displayed on D7-D0

The above program adds two 16-bit integers, located in memory address 16H and 18H. This could accept larger integers, for example 32-bit integers by changing steps 3 and 8 to values 4 and 20H respectively, and then input would be in 16H and 20H. Numbers are represented in memory as little endian.

Example: 14 + 15 = 29 = 1DH = 00 011 101

Example: 1234 +たす 4321 = 5555 = 15B3H = 00 010 101, 10 110 011

This will add two integers of nearly any size (16, 32, 64-bit, etc) using an Intel 8080 , 8-bit CPU. This is implemented as a full program, running on a MITS Altair 8800.

Step Switches 0-7 Control Switch Instruction Comment
1 RESET
2 00 001 110 DEPOSIT MVI C, 2 ; loop counter set to word size
3 00 000 010 DEPOSIT NEXT ; value is 2
4 00 010 001 " LXI D, 16H ; load address of first term into E:D
5 00 010 110 " ; at memory address 16H
6 00 000 000 " 
7 00 100 001 " LXI H, 18H ; load address of second term into H:L
8 00 011 000 " ; memory address 16H + word size = 18H
9 00 000 000 " 
10 10 101 111 " XRA A ; clear accumulator
11 00 011 010 " LOOP:LDAX D ; load [E:D] into A
12 10 001 110 " ADC M ; add [H:L] + previous carry, to A
13 00 010 010 " STAX D ; store result in A to [E:D]
14 00 001 101 " DCR C ; decrement loop counter
15 11 001 010 " JZ DONE ; if counter is zero, end addition
16 00 010 101 " ; jump to step 23
17 00 000 000 " 
18 00 010 011 " INX D ; first term next byte
19 00 100 011 " INX H ; second term next byte
20 11 000 011 " JMP LOOP ; restart loop
21 00 001 001 " ; jump to step
22 00 000 000 " 
23 01 110 110 " DONE:HLT ; halt CPU
24 00 001 110 " ; Term 1 low byte (14) 
25 00 000 000 " ; Term 1 high byte (0)
26 00 001 111 " ; Term 2 low byte (15) 
27 00 000 000 " ; Term 2 high byte (0) 
31 RESET ; Reset program counter to beginning
32 RUN
33 STOP 
34 00 010 110 EXAMINE ; low byte of output displayed on D7-D0
35 EXAMINE NEXT ; high byte of output displayed on D7-D0

The above program adds two 16-bit integers, located in memory address 16H and 18H. This could accept 32-bit integers by changing steps 3 and 8 to values 4 and 20H respectively, and then input would be in 16H and 20H. Numbers are represented in memory as little endian.

Example: 14 + 15 = 29 = 1DH = 00 011 101

Example: 1234 +たす 4321 = 5555 = 15B3H = 00 010 101, 10 110 011

This will add two integers of nearly any size (16, 32, 64-bit, etc) using an Intel 8080 8-bit CPU (c. 1974). This is implemented as a full program, running on a MITS Altair 8800.

Step Switches 0-7 Control Switch Instruction Comment
1 RESET
2 00 001 110 DEPOSIT MVI C, 2 ; loop counter set to word size
3 00 000 010 DEPOSIT NEXT ; value is 2
4 00 010 001 " LXI D, 16H ; load address of first term into E:D
5 00 010 110 " ; at memory address 16H
6 00 000 000 " 
7 00 100 001 " LXI H, 18H ; load address of second term into H:L
8 00 011 000 " ; memory address 16H + word size = 18H
9 00 000 000 " 
10 10 101 111 " XRA A ; clear accumulator
11 00 011 010 " LOOP:LDAX D ; load [E:D] into A
12 10 001 110 " ADC M ; add [H:L] + previous carry, to A
13 00 010 010 " STAX D ; store result in A to [E:D]
14 00 001 101 " DCR C ; decrement loop counter
15 11 001 010 " JZ DONE ; if counter is zero, end addition
16 00 010 101 " ; jump to step 23
17 00 000 000 " 
18 00 010 011 " INX D ; first term next byte
19 00 100 011 " INX H ; second term next byte
20 11 000 011 " JMP LOOP ; restart loop
21 00 001 001 " ; jump to step 11
22 00 000 000 " 
23 01 110 110 " DONE:HLT ; halt CPU
24 00 001 110 " ; Term 1 low byte (14) 
25 00 000 000 " ; Term 1 high byte (0)
26 00 001 111 " ; Term 2 low byte (15) 
27 00 000 000 " ; Term 2 high byte (0) 
31 RESET ; Reset program counter to beginning
32 RUN
33 STOP 
34 00 010 110 EXAMINE ; low byte of output displayed on D7-D0
35 EXAMINE NEXT ; high byte of output displayed on D7-D0

The above program adds two 16-bit integers, located in memory address 16H and 18H. This could accept larger integers, for example 32-bit integers by changing steps 3 and 8 to values 4 and 20H respectively, and then input would be in 16H and 20H. Numbers are represented in memory as little endian.

Example: 14 +たす 15 = 29 = 00 011 101

Example: 1234 +たす 4321 = 5555 = 00 010 101, 10 110 011

Source Link
640KB
  • 12.4k
  • 2
  • 38
  • 61
Loading

AltStyle によって変換されたページ (->オリジナル) /