News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Assembly and array

Started by danglin, February 12, 2005, 07:02:13 PM

Previous topic - Next topic

danglin

I have two questions that is driving us crazy. Can one of you genius take a look and see if you can work your magic. Attached file is the question and answer given to the problems. Below are the questions for the GAL (General Assembly langauge)

Question 27:

Write a GAL subprogram called min, which finds the smallest value in an array of 100 integers. Assume the base address of the array is given in reg0, and return the smallest value in reg1. Any other registers that your subprogram modifies should be saved and restored to their original states.



Question 31:

Rewrite your answer to Question 27, using  a stack to pass parameters according to the following model,

Return_address    <------SP(top-of-stack register)
Array_base
Var_location

System stack



Where the value contained in var_location is the address where the smallest value in the array should be stored. Assume that reg7 is acting as SP, the top-of stack pointer.



[attachment deleted by admin]

pbrennick

This sounds like homework?  Am I wrong?
Paul

sluggy

Quote from: danglinWrite a GAL subprogram called min, which finds the smallest value in an array of 100 integers. Assume the base address of the array is given in reg0, and return the smallest value in reg1. Any other registers that your subprogram modifies should be saved and restored to their original states.
This is simple!! reg0 contains the beginning address, you add the sizeof<integer> to it up to 99 times (i.e. it is a loop), when you start the loop you take the first value, and compare it to each subsequent value, swapping the new value into reg1 if it is less than the old value in reg1.



Quote from: danglinRewrite your answer to Question 27, using  a stack to pass parameters according to the following model,

Return_address    <------SP(top-of-stack register)
Array_base
Var_location

System stack

Where the value contained in var_location is the address where the smallest value in the array should be stored. Assume that reg7 is acting as SP, the top-of stack pointer.
In this one you are creating your own stack frame, and the parameters are being PUSHed in stdcall format (right to left). var_location is a pointer to where you should store the smallest value once you have determined it. Very little has to be rewritten from Q27, this question is mainly adding a little more complexity to the same answer. These two questions are not really teaching you asm, they are just using asm as a tool to teach you *concepts* that can apply to just about any language.


You don't know just how lucky you are to have even got that answer, as we have strict rules about people asking homework/assignment questions in this forum. In future, try to do some of the work yourself before asking questions, that way we know you are learning at least a little bit.


danglin

Thanks Sluggy. You are correct when you said that these questions are not teaching me asm -- that's why I guess I don't spend too much resource/energy on AL. After reading your replies to the answers, I actually got a better idea how to solve them in GAL. Thanks for the replies!