1

im starting on assembly programing and trying a few exercices, im stuck on declaring an array of integers so i can later sum that array, im using 6502 emulator (6502 Macro Assembler, Simulator, and Debugger http://exifpro.com/utils.html) and getting the "Illegal byte code encountered" error. I have tryed several ways to create the array, the last of them was this:

*= $600

array:

.DB "1", 0
.DB "1",0
.DB "4",1
.DB "3",1

appreciate any help.

Luiz Topin
  • 21
  • 2
  • NUMBERS DW 34, 45, 56, 67, 75, 89 – Vikram Palakurthi Apr 01 '18 at 21:19
  • http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm refer to Data Declarations for examples on declaring an array – Vikram Palakurthi Apr 01 '18 at 21:22
  • Which assembler do you use? And emulator? That error is from compilation (assembling), or from runtime? Because that last try doesn't show any code at all, but the error sounds like runtime one, which makes sense, no code = some bogus data were run instead = error. – Ped7g Apr 01 '18 at 21:22
  • NUMBERS: .DW 34, 45, 56, 67, 75, 89"Illegal byte code encountered" – Luiz Topin Apr 01 '18 at 21:25
  • im using 6502 Simulator, it actualy compiles, but when im debugging, at the registers and status window, im getting the error msg and it stucks – Luiz Topin Apr 01 '18 at 21:27
  • so where's your code? Some instruction to execute? What do you expect your code to do, if it's just data? If it compiles, it "works" (does all it can do). You need to add some code to make this example meaningful. Maybe you struggle to set up correct entry point to the code? Which 6502 simulator? 6502 is just CPU, there're several systems using this CPU in real world, some of them being quite different by design, with several assemblers being available, each may have different syntax, etc... is this about that simplified web 6502 sim? Put url in question then, it helps a lot. – Ped7g Apr 01 '18 at 22:44
  • 2
    Maybe also you didn't yet realize, that from the CPU point of view there's no distinction between data and code? The CPU will read instruction opcode from memory, memory stores byte values. There's no flag which cell of memory was set by instruction or by data, for example on Z80 CPU the byte value `201` is instruction `ret`, whatever means you did use to store the `201` into memory. If you use it in calculation, it's 201, if you execute it, it's `ret`. So if you declare your array in memory and it compiles, there're some values in memory, which you don't want to execute (not even by accident) – Ped7g Apr 01 '18 at 22:49
  • @Ped7g Thanks for the advice, i put the link and the emulator name (i tought it was 6502 emulator the actual name) into the question, im trying to make a simple sum of the elements in the array, the first thing im trying to do is to create the array, then load the first element of the array and store it on other variable like so: ` *= $600 NUMBERS: .DW 1,2,3 test = $e001 LDX #0 LDA NUMBERS, X STA test BRK ` – Luiz Topin Apr 01 '18 at 23:33
  • 1
    Check code samples "Test liba.65s" from the web page. You can see the first instruction line is `JSR _print_string`, jumping over the data. So now I'm pretty sure your problem is, that you did put your array at the beginning where the simulator is actually expecting first instruction, so the bytes 1, 2, 3 (or 1, 0, 2... when defined by `.dw`) get executed as instructions. You can use the debugger before executing first instruction to see where it points to, and what kind of disassembly does it provide for such bytes (if the debugger is capable enough to handle this and stop ahead of 1st ins.). – Ped7g Apr 02 '18 at 01:00
  • 1
    Actually this one even mentions 6502 in answer: https://stackoverflow.com/questions/2022489/how-instructions-are-differentiated-from-data – Ped7g Apr 02 '18 at 01:11
  • I mistaken yours 6502 simulator hint with this one (appearing in other SO question just few hours before yours): https://skilldrick.github.io/easy6502/ you may even check this one too, maybe it will help with learning to see somewhat different configuration of the same CPU, with a bit different assembler syntax/etc, that may gave you good idea about the fragmented real world of assembly. :) – Ped7g Apr 02 '18 at 08:42
  • @Ped7g There's no way this question is a duplicate of the one referenced. Clearly there is a programming error in that the simulator is trying to execute something that is not a valid opcode (although its behaviour is different in this respect to a real 6502). There's a programming bug that needs diagnosing and the question as currently written falls way short in that respect, but the alleged duplicates are unhelpful. – JeremyP Apr 18 '18 at 16:03
  • 1
    @JeremyP no, the source code in this question defines data bytes in the place where the simulator starts execution, the OP was missing the information that data bytes are still only bytes, can't be distinguished from instruction bytes by CPU, so the CPU happily tried to execute OP's data => invalid opcode. I mean, it's direct answer why his problem occurs, but you have to understand what is going on. – Ped7g Apr 18 '18 at 16:15
  • 1
    @Ped7g " the OP was missing the information that data bytes are still only bytes" but that is not the answer to the question. The answer to the question is "the simulator is executing data as if it were code". Fiurthermore, this is a problem specific to the simulator because a real 6502 would not stop, it would happily execute the opcodes, producing undocumented results. – JeremyP Apr 19 '18 at 08:55
  • @JeremyP yes, it's not perfect duplicate, and not perfectly straightforward answer. I'm concerned only if it was enough for OP, but feel free to reopen+answer better. (if this is not even offtopic as sort of simple typo) – Ped7g Apr 19 '18 at 09:00

0 Answers0