-2
  1. For my first question, let's assume we have the following line of code under .data:

    "theSINTArray BYTE 256 dup(?)". 
    

    I know that this code creates an array in which each element must be a BYTE, but what are the 256 and dup(?) there for?

  2. I know that the code below pushes the type, length and offset/address of theSINTArray onto the stack, but what I would like to know is if it is possible to retrieve them from the stack and utilize them within a subroutine.

    main PROC
    
    push    TYPE theSINTArray
    push    LENGTHOF theSINTArray
    push    OFFSET theSINTArray
    call    testParameters
    exit
    
    main ENDP
    
  3. This is a bit of a tedious question, so I apologize in advance, but I simply don't understand why a large portion of the lines in the code sample below are necessary. Assuming I have the line "prompt BYTE "Please enter a value: ",0" in the .data section, what is the purpose of each line of the code below? Note: WriteString and ReadString are subroutines defined in Irvine's library, which I am using.

    testOutput PROC
    
    push    edx
    push    ecx
    mov     edx,offset prompt
    call    WriteString
    pop     ecx
    pop     edx
    call    ReadString
    ret
    
    testOutput ENDP
    
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Proto
  • 99
  • 5

1 Answers1

4

what are the 256 and dup(?) there for?

Read the assembler's manual. TL;DR: reserves 256 uninitialized bytes

if it is possible to retrieve them from the stack and utilize them within a subroutine

Of course it is possible, argument passing would be silly if the callee couldn't access the arguments ;) You address them relative to esp (the stack pointer), or, after you have set it up as frame pointer, ebp. Examples: [esp+4] or [ebp+8].

what is the purpose of each line of the code below

testOutput PROC            ; begin testOutput procedure

push    edx                ; save edx on stack
push    ecx                ; save ecx on stack
mov     edx,offset prompt  ; load edx with address of prompt
                           ; presumably argument to WriteString
call    WriteString        ; invoke WriteString procedure
pop     ecx                ; restore ecx saved above
                           ; in case WriteString modified it
pop     edx                ; restore edx saved above (we have modified it)
call    ReadString         ; invoke ReadString procedure
ret                        ; return from subroutine

testOutput ENDP            ; end of procedure
Jester
  • 56,577
  • 4
  • 81
  • 125
  • Jester, your response definitely improved my understanding of the code samples, but I do have 2 remaining questions. For the first code example, when you say "reserve", do you mean set the number of indexes in the array? So "256 dup(?)" makes it so that theSINTArray has 256 indexes? Also, what would happen if the question mark next to dup was replaced with a different character such as a number? – Proto Apr 04 '16 at 19:43
  • In other words, it allocates a 256 byte array, not initialized to any particular value you care about. If you do care, you can of course give that value instead of the `?`. – Jester Apr 04 '16 at 19:48
  • Oh, now I understand the value within the parenthesis is used to initialize the value that is stored in each byte. Thank you for your help, Jester. – Proto Apr 04 '16 at 19:51