LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-25-2008, 07:42 AM   #1
Nejad
LQ Newbie
 
Registered: Nov 2006
Posts: 9

Rep: Reputation: 0
Assembly Program Question??


Hi All,

i am tray to solve this question But all my attempts is failed, I look forward to your responses.

Q) assembly program that defines a 2D array of words and find the following:
- The maximum element in the array.
- The minimum element in the array.
- The average of all elements in the main diagonal.

Notes:
- Your program must work for any square matrix size. 2X2, 3X3, 4X4 ..


thanks and best regards
 
Old 12-25-2008, 07:55 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
If you are going to post homework questions, here a a few guidelines:
  1. Acknowledge that it is homework (but not by cutting and pasting the assignment)
  2. Show the work you have done so far
  3. Give information on the class, topics already covered, books used, etc.
  4. Ask specific questions---"why does this line produce this error?"

Last edited by pixellany; 12-25-2008 at 07:58 AM.
 
Old 12-25-2008, 08:46 AM   #3
Nejad
LQ Newbie
 
Registered: Nov 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
If you are going to post homework questions, here a a few guidelines:
  1. Acknowledge that it is homework (but not by cutting and pasting the assignment)
  2. Show the work you have done so far
  3. Give information on the class, topics already covered, books used, etc.
  4. Ask specific questions---"why does this line produce this error?"
Hi,

This is not a homework questions, I prepare for the final exam in assembly and for that I resolve many questions.

thanks and best regards
 
Old 12-25-2008, 10:42 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Well.....there's a fine line between homework and preparing for an exam.

Show us the work you have done so far and tell us what specific issues you are having.
 
Old 12-26-2008, 02:35 AM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Ah, the sweet smell of homework in the morning (I know you think this isn't homework, but it is to me):
You won't like me saying this, but if you have done the course and genuinely have no clue about the question, there is an argument that you deserve to fail.
I assume, therefore, that you have some clue but not enough of a clue to actually complete the question. In this case, you will understand that it is easier to help if the rest of us have some clue about which parts you know (or think that you know) and which parts you don't
  • At some point, for any question of this type, you will need an algorithm; is this (or have you been doing) a course in algorithms or assembler or something else? On the face of it, the requirement that it is an assembler program is a slightly odd one; in most cases, the answer to a question like this would involve the algorithm, but here it may be assembly code that demonstrates understanding and fragments of assembler may be required (at least in your head; maybe you don't need to write it all down). If it is assembler that you have been studying, you probably should say more about which one.
  • By 'words' I assume that it is meant a unit of storage twice the size of a byte (and not units of text of variable length, which would complicate things)
  • My interpretation is that the maximum element is the element with the maximum value (and not the maximum index). This is odd, as it is a function of representation (you could be representing floating point values (but probably aren't), text, bcd... data types and you may be doing different comparisons based on your data type. If this were about the algorithm, you could hide this 'detail', but the question is about assembler.
  • Same applies to minimum.
  • For some data types 'average' would be a slightly unusual concept. Maybe you can presume that that the data would not be of a type for which average is not an obviously meaningful concept, and for others it maty just be difficult to work with.
 
Old 12-26-2008, 09:44 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Nejad View Post
I prepare for the final exam in assembly
So it is a bit late to start learning the basic concepts.

Quote:
Originally Posted by salasi View Post
At some point, for any question of this type, you will need
You provided an amazingly large amount of information, both more than the question deserved and more than the OP would have a clue how to understand.

You might have been better off checking the OP's other thread, which might give you an even lower estimate for the level of information he is ready to absorb.

http://www.linuxquestions.org/questi...sembly-693010/

Quote:
This is odd, as it is a function of representation
Most quoted homework assignments you see online are flawed in that same way. They leave out major pieces of information so that any experienced programmer looking at the assignment would say they haven't really told you what to do.

The optimistic view would be that all the missing information was covered in class. In this case, the instructor might have taught a subset of assembly programming in which "word" always meant a signed 16 bit integer. That highlights the other big problem with helping on homework questions. The OP apparently wasn't listening in class and none of us were listening in the OP's class either.

Quote:
Originally Posted by pixellany View Post
Show us the work you have done so far and tell us what specific issues you are having.
Of course I might be underestimating the amount the OP has learned so far in this class, in which case Pixellany's comment is all any of the experts here really needed to say.

Last edited by johnsfine; 12-26-2008 at 09:47 AM.
 
Old 12-26-2008, 10:02 AM   #7
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by Nejad View Post
Q) assembly program that defines a 2D array of words and find the following:
- The maximum element in the array.
- The minimum element in the array.
- The average of all elements in the main diagonal.

Notes:
- Your program must work for any square matrix size. 2X2, 3X3, 4X4 ..
This is a very basic stuff, even for assembly. If you seriously can't do it yourself, ask friend or classmate (or someone else) to do it for you in exchange for something. If you want help here, then post a listing of program you tried to write. If you can't do that, then search for some assembler tutorials.
 
Old 12-27-2008, 05:21 AM   #8
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by johnsfine View Post
You provided an amazingly large amount of information, both more than the question deserved and more than the OP would have a clue how to understand.
Perhaps I was being far too optimistic, but my interpretation was that the OP might know a few things, but had no ability to ask a question that was directed/focussed/adequate for the requirements.

In particular, the OP probably has a considerable amount of context that the rest of us just don't have; maybe the 'thought process' behind this is 'I won't need to tell these people that; they seem like experts to me, and they must know that' which is, at least, questionable when it comes to things like the level of knowledge of the OP.

The other interpretation, that the OP has got to the end of a course on assembler programming and hasn't yet absorbed some of the concepts that would have been necessary in the first half hour for any of the rest of the course to make sense is just too horrible to contemplate (but may be true) and would probably mean that any information entered here is unhelpful (to the OP...maybe, subsequently, others will be helped).
 
Old 12-27-2008, 05:51 AM   #9
"SMS"
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Rep: Reputation: 0
Quote:
Originally Posted by Nejad View Post
Hi,

This is not a homework questions, I prepare for the final exam in assembly and for that I resolve many questions.

thanks and best regards
what a coincidence then, because I happen to have the same same question as an assignment, don't make me post the link, college mate.

anyway, I solved the problem, it's very easy even for newbies like us, try to do it yourself to gain better understanding of assembly and be able to pass the final, good luck.

btw, I will report any solution posted here, on yahoo answers or on "free the penguin" to wagih/tuqa/aws so don't bother.
 
Old 12-28-2008, 10:17 AM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by "SMS" View Post
anyway, I solved the problem, it's very easy even for newbies like us,
I'm just curious (hopefully no expert here would use your answer to this to help in posting sample code):

What is a "word" in the context of your assignment? Is it a signed 16-bit value or an unsigned 16-bit value or something else? Did the instructor make that clear somewhere outside the quoted assignment?

Where is the input data supposed to come from? (the number indicating the size of the array as well as the data filling that array).

"assembly program that defines" seems to hint that all that would be just hard coded into the program itself, but "must work for any square matrix size" hints the other way.

I/O from assembly language is relatively hard, certainly much harder than all the processing described in this assignment. I'm curious about how your instructor gets around that issue: a beginning assembly programmer at the level at which the processing in this assignment would be useful practice would be far below the level at which the I/O needed to make it a real program would be possible without help.

I would think assembly assignments (like most real world assembly work) should be for subroutines, not programs. The instructor ought to provide the wrapping that makes the subroutine into a usable program (probably in the form of a main function written in C).

Last edited by johnsfine; 12-28-2008 at 10:18 AM.
 
Old 12-29-2008, 08:44 AM   #11
"SMS"
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Rep: Reputation: 0
Quote:
What is a "word" in the context of your assignment? Is it a signed 16-bit value or an unsigned 16-bit value or something else? Did the instructor make that clear somewhere outside the quoted assignment?
well, the course we're attending is a very simple introductory course about intel microprocessors since the 8086 software and hardware, it uses MASM compiler. a "word" is what you define with the "DW"(define word) directive.

Quote:
Where is the input data supposed to come from? (the number indicating the size of the array as well as the data filling that array).

"assembly program that defines" seems to hint that all that would be just hard coded into the program itself, but "must work for any square matrix size" hints the other way.

I/O from assembly language is relatively hard, certainly much harder than all the processing described in this assignment. I'm curious about how your instructor gets around that issue: a beginning assembly programmer at the level at which the processing in this assignment would be useful practice would be far below the level at which the I/O needed to make it a real program would be possible without help.
you're absolutely correct john; the topics we covered in this course about I/O are far from enough to give us an idea how to accomplish the I/O needed for this program. The matrix is hard coded into the program and with a fixed size, and what they mean by "should work for any matrix size" is that any modifications to matrix in the data segment (as in, changing its values or size) will need no modifications to the code in the code segment so that the program will continue to work correctly.

Quote:
I would think assembly assignments (like most real world assembly work) should be for subroutines, not programs. The instructor ought to provide the wrapping that makes the subroutine into a usable program (probably in the form of a main function written in C).
well, yes, but the instructor left out some details vague so that each student will think of a different solution and catch cheaters more easily
 
Old 12-29-2008, 09:08 AM   #12
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by "SMS" View Post
a "word" is what you define with the "DW"(define word) directive.
Maybe you are missing an important detail here.

What you define with DW might be a signed 16-bit integer or an unsigned 16-bit integer (It might be many other things as well, but not in the context of this simple assignment).

The code you write for min and max and average, etc. would be different for signed vs. unsigned.

Attention to that type of detail should be a big part of an introduction to assembly programming.

In a high level language you declare your variables in a way that implies signed or unsigned and then the compiler keeps track of the details.

In asm, the programmer must know which operations differ for signed vs. unsigned and think about which should be used in each place that requires such an operation.

To do a good job on "average" of 16-bit values, you really ought to accumulate a 32-bit sum and then do a 32-bit by 16-bit divide to produce a 16-bit result.

If you only maintain a 16-bit sum of 16-bit values, that method of computing the sum would be the same for signed vs. unsigned values. But if you compute a 32-bit sum of 16-bit values, the method of computing the sum is different for signed vs. unsigned.

Either way, the method of dividing to produce the average is different for signed vs. unsigned. And of course, the instruction choice for branching after a compare when finding min or max is different for signed vs. unsigned.
 
Old 12-29-2008, 10:56 AM   #13
"SMS"
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Rep: Reputation: 0
Quote:
Originally Posted by johnsfine View Post
What you define with DW might be a signed 16-bit integer or an unsigned 16-bit integer (It might be many other things as well, but not in the context of this simple assignment).
what I mean is that "word" (in the context of this assignment) only indicates the length of bits representing the data (16) rather than what type of data is stored.

of course 16bits can contain many types of data, they may be 16bit Unicode characters or even packed/unpacked BCD numbers or anything else, but a general rule in solving any programming/engineering problem is that we always assume the simplest/most-common/easiest case unless otherwise stated in the problem, for example, if you were asked about the acceleration of a free falling object given its mass you simply multiply m by g, and don't need to complicate yourself with other details as initial velocity/friction due to air/friction due to dust/attraction force between the object and the moon!

Last edited by "SMS"; 12-29-2008 at 10:57 AM.
 
Old 12-29-2008, 12:23 PM   #14
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by "SMS" View Post
<snip> but a general rule in solving any programming/engineering problem is that we always assume the simplest/most-common/easiest case unless otherwise stated in the problem</snip>
If that's your general rule, I certainly hope you are neither an engineer nor a programmer!

I'm not an engineer, but I've programmed for several decades and my general rule was "always identify and verify and assumptions made by your code." If, for example, the "easiest case" is a 16-bit unsigned integer, then I'd write an assertion macro to test that assumption (as far as possible) and use it in the code.
 
Old 12-29-2008, 12:45 PM   #15
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Sorry guys, but I think it's time to but this one to bed. I think the OP got the point.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BSD: Problems executing an assembly program BiThian Programming 7 01-10-2007 11:40 AM
hash routine into assembly program rblampain Linux - Security 3 08-06-2005 01:49 AM
Problem linking assembly program with C lib. 95se Programming 1 03-08-2005 09:44 PM
Please help me with my assembly program flamesrock Programming 2 01-30-2005 10:27 PM
puzzle about g++ compile options for inline assembly program markbeth Programming 2 09-20-2004 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration