1

I tried going through the documentation I have but it's really confusing, I need to understand this for an exam but I'm having lots of troubles.

  aseg
  org  100h
start:  ld    ix, vector 
        ld    B, amount
        ld    A, 0
cycle:  add   A, (IX)
        jp    PE, fail
        inc   IX
        djnz  cycle
        ld    (resp), A
        jp    fin
fail:   ld    A, 1
        ld    (error), A
fin:    rst   38h
vector: db    12,7,9,21
amount  equ   $ - vector
resp    ds    1
error:  db    0
        end   start

I understand what most of the 'functions' (ld, add, jp, inc) do separately, what I don't understand is:

1) What value is loaded into IX in the first line? (the variable?) vector has 4 values on it, I tried this in a z80 simulator and it says that IX gets the value 0019, but I don't see where this is coming from...

2) Am I understanding correctly that "vector: db 12,7,9,21" creates an array with the values 12,7,9,21?

3)What does the line "end start" do?

4)What value is "amount" holding?

YoTengoUnLCD
  • 600
  • 7
  • 15
  • 1
    Is some company or school *actually* using the z80!? That was obsolete in 1983. – wallyk Jun 10 '15 at 19:57
  • @wallyk My university teaches it (although we don't really use it for anything practical) on the first year of software engineering. I don't get why this is getting downvoted... – YoTengoUnLCD Jun 10 '15 at 19:58
  • A specific question would be like *What does the `ld` instruction do?* A question saying "explain what this does" is too broad according to SO rules. See the [site overview](https://stackoverflow.com/tour). – wallyk Jun 10 '15 at 20:02
  • I understand, I will edit my question in a minute. Sorry about it, this is my first post on this SE. – YoTengoUnLCD Jun 10 '15 at 20:03
  • 1
    @wallyk TI is still using them for one, in some of their graphing calculators. – harold Jun 10 '15 at 20:09
  • 1
    @JoseManuelAbarcaRodríguez see [his profile](http://stackoverflow.com/users/4996524/yotengounlcd?tab=reputation) ... you get 100 rep if you associate your user with another site. – Jester Jun 10 '15 at 20:13
  • 1
    It's actually 101. It goes to show one can be an expert in other fields than just programming. – Jongware Jun 10 '15 at 20:15
  • I made my question a lot more specific, how do I reopen it? – YoTengoUnLCD Jun 10 '15 at 20:15
  • 2
    You wait until you get enough reopen votes :) In the meantime, **1)** loads the address of `vector` **2)** yes **3)** signals the end of your code and sets up `start` as entry point **4)** the length of the vector, and that's probably a copy-paste error because that should be `amount` (as that is how it's loaded earlier) – Jester Jun 10 '15 at 20:20
  • @Jester Sorry if this is too much but I have many doubts: If vector has many values, shouldn't every value have it's own memory adress (if so, what value is being hold by the adress of vector)? Also, yes, that should be amount (the code had spanish words so I tried to make it a bit more understandable). Thank you so much! – YoTengoUnLCD Jun 10 '15 at 20:24
  • 3
    `vector` is a label that marks an address (like a bookmark). It doesn't know or care that you used it for a list. As such, it's the address of the first element (the same as in C, accidentally). – Jester Jun 10 '15 at 20:26
  • 1. IX is loaded with the address of vector (should be 119 not 19, since there is a org 100 h. 2. yes. 3. end start - end of the source code, with the starting address of "start", = 100h. 4. amount = $-vector, $ is current address so $-vector = current address - address of vector = number of bytes in vector . JP PE, fail checks for overflow (overflow and parity states share the same flag bit). – rcgldr Jun 10 '15 at 21:17
  • Some of your questions are not related to "Z80 assembler", but are for a *specific* assembler. You are asking about what single instructions do, and about this specific assembler *syntax*. The syntax should be explained in your assembler's documentation. Examples: the `end start` line, the `amount` value. – Jongware Jun 10 '15 at 21:34

1 Answers1

3

Let's take these one at a time:

1) What value is loaded into IX in the first line? (the variable?) vector has 4 values on it, I tried this in a z80 simulator and it says that IX gets the value 0019, but I don't see where this is coming from...

The line ld ix, vector loads the memory address for vector into IX. When you see 0019 show up here in your simulator you are looking at the byte offset from the start of the program. This is essentially being used as a pointer to the first element in that "array."

2) Am I understanding correctly that "vector: db 12,7,9,21" creates an array with the values 12,7,9,21?

Well, you could view it that way. All that it's really doing is defining four arbitrary bytes in RAM and providing a convenient label to figure out where they are. How the data is interpreted is what determines if it's an array, four characters, a two byte integer or a four byte integer, etc.

3)What does the line "end start" do?

This is just a directive to the assembler. It actually does nothing with regard to the assembled code. It lets the assembler know that there should not be any more code coming.

4)What value is "amount" holding?

Amount is a defined value (rather than allocated memory) that is calculated at compile time. The $ in an assembler typically refers to the current address. Therefore, Amount is defined as the difference between the current address and the address where vector starts. In this case, since there are four bytes defined, this will work out to a value of 4.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67