A friend of mine was given 8080 assembly code as part of a puzzle he's trying to solve. This is the code:
3E 02
4F
C6 04
47
11 41 01
21 69 00
19
76
He needs the values of B, DE, C and HL
Can anyone solve this or point me in the right direction on how to run this?
Up开发者_如何学Godate
Spoiler: The solution seems to be:
C = 02, B = 06, D = 01, E = 41, H = 01, L = AA
Here's a guide to the 8080 instruction set: http://www.comsci.us/cpu/8080/isindex.html Your hex listing looks like an instruction stream; you should be able to go from there. How delightfully old-school!
Good luck.
For reference, here's the disassembly:
3E 02 mvi a, 2 ; Move o1 <- immediate data
4F mov c, a ; Move o1 <- o2
C6 04 adi 4 ; Add immediate to A
47 mov b, a ; Move o1 <- o2
11 41 01 lxi d, 141h ; Load register pair with immediate data
21 69 00 lxi h, 69h ; Load register pair with immediate data
19 dad d ; Add register pair to HL
76 hlt ; Halt
You need to disassemble it.
That is, convert the hex op codes in to their mnemonics.
Here's an example reference.
You can see from this that 3E is "MVI A, d8", so that looks like 3E 02 is putting the value 02 in to the A register.
Once you've decoded the mnemonics, you can look up what they actually mean and figure out the program.
Easy enough to do by hand.
Complete spoiler
0000h: 3e02 mvi a, 2h ; A = 20002h: 4f mov c, a ; C = 20003h: c604 adi 4h ; A = 60005h: 47 mov b, a ; B = 60006h: 114101 lxi d, 141h ; DE = 0141h0009h: 216900 lxi h, 069h ; HL = 69h000ch: 19 dad d ; HL = 69h + 141h = 1aah000dh: 76 hltA = 6, B = 6, C = 2, D = 1, E = 41h, H = 1, L = 0aah
An 8080 online disassembler here.
An 8080 online instruction set reference here.
You don't need to run it - you just need to translate it. A table of 8080 opcodes like this, 10 minutes work and you will have disassembled the code. You can then simulate it mentally to work out the answer.
Judging by this, your best bet would be to do a search for an 8080 emulator and run it against the emulator, and get the answer from it.
Hope this helps, Best regards, Tom.
3E 02 ;mvi a, 02h -- load A with 02h
4F ;mov c,a -- move A into C (A remains 02h)
C6 04 ;adi 04h -- a = a + 04h (A now contains 06h)
47 ;mov b,a -- BC pair now contains 0602h
11 41 01 ;lxi d, 0414h -- DE now contains 0141h
21 69 00 ;lxi h, 0069h -- HL now contains 0069h
19 ;dad d -- HL = HL + DE
76 ;hlt -- halt processing
精彩评论