0

I'm writing a subroutine display(Z, n, flag), where Z is an int/ string array, n is the length of the array and the flag indicates if Z is an address of string or integer array.

Based on the value of the flag, the subroutine either displays Z as a byte array of length n, displaying each byte as a character, or it displays Z as an integer array.

And here's where the confusion is. I'm having a hard time understanding how to differentiate between the 2 address. I feel like this is something incredibly basic but I just can't seem to figure it out. Any/all ideas would be appreciated!

2
  • Integer must be incremented by 4 when indexing. Commented Dec 16, 2015 at 10:40
  • Your question is very ambiguous. Is Z always an array (of either type) or is Z sometimes an integer array and sometimes a single string? Given this ambiguity user @Fifoernik has provided you with a decent answer. Commented Dec 20, 2015 at 18:02

1 Answer 1

1

where Z is an int/ string array

If Z is the address of an array of integers, the address points at dwords that contains the actual numerical value of these integers.

mov ebx, Z
mov eax, [ebx]    ;value of 1st integer
mov eax, [ebx+4]  ;value of 2nd integer

If Z is the address of an array of strings, the address points at a list of addresses that each point at a string in memory.

mov ebx, Z
mov esi, [ebx]    ;address of 1st string
mov al,  [esi]    ;1st character of 1st string
mov al,  [esi+1]  ;2nd character of 1st string
...
mov esi, [ebx+4]  ;address of 2nd string
mov al,  [esi]    ;1st character of 2nd string
mov al,  [esi+1]  ;2nd character of 2nd string

n is the length of the array

n says how many elements there are in these arrays. In the case of an array of strings, the length of an individual string is determined by finding the terminating zero.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.