?
Solved

New to assembly and having trouble with doing some math

Posted on 2004-09-05
6
Medium Priority
?
242 Views
Last Modified: 2006-11-17
Good evening, how are you doing? I am sorry to bother everyone, however I am new to programming in assembly and there seems to be to much magic going on in my text book I am reading. What I want to understand is if a user inputs lets say Width =2, Lenght =3, and Height=4 and I want to know what they entered in each indvidual one to do some math, such as multiplying adding and etc...... How would I do that in assembly. All the book keeps showing me is one input not more then one. Thanks
0
Comment
Question by:Corey_819
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:aib_42
ID: 11986296
First of all, the method reading user input would depend on the platform/environment you're running your assembly program on. For example, a program running on no operating system at all (ie an OS in itself) might use BIOS to access the keyboard (and the monitor) and get input and display it to the user. An assembly program using a CRT (C Runtime) Library might use the ever-popular printf and scanf functions. An assembly program running in Windows might display a textbox for the user to fill in, or hook the keyboard and monitor it for keypresses! Getting the numerical value of an input would depend on the environment as well.

Now for doing math, you have the best source reserved for you: The CPU! Before/while learning assembly, you should also learn about the CPU and how to use it. For example, if you knew how it worked, you would know that it does standard integer arithmetic using _registers_ as temporary storage and _instructions_ for... well, instructing what arithmetic operation to do :). Here is a very basic x86 assembly program:

mov ax, 0010
add ax, 0010

This would load '10' - whatever that means, for for some assemblers, it means 10 decimal and for others, it means 10 hexadecimal, which is 16 decimal, check your assembler documentation for syntax details - to the register ax with the first instruction. It would then add 10 (decimal or hexadecimal depending on how your assembler sees and encodes it) to it with the second instruction, and you would have ax equaling 20. (again, 20 or 32)

I don't have any links to any assembly tutorials handy, but go give google a try. Other experts might give you links as well.
0
 
LVL 1

Author Comment

by:Corey_819
ID: 11993605
Thanks for the help aib_42. What I am trying to do is the user will run it from a dos window type the compiled exe and then enter the length, height, and widht. What I am confused is in assembly how do you know what values the user entered in the height, width, and length. I mean in c++ you would have variables. How would you do that in assembly. I understand the registers. I am just having a hard time understanding this first part. Thanks again.
0
 
LVL 7

Accepted Solution

by:
aib_42 earned 100 total points
ID: 11997376
Well, depending on the functions you use, data may be stored on a fixed location in memory, it may be returned on some registers, or may be put on an arbitary location on memory whose address is returned in a register.

Take the malloc() call from the C Runtime Library, for example. Its mission is to allocate memory. It takes its one parameter from the stack, the size of memory to allocate, allocates that many amount of bytes, and returns the address of the allocated memory in eax (or 0 on failure).

Take scanf() for another example. With scanf(), you supply it the location(s) to store the user input. Before calling it, you push on the stack a pointer to a string which specifies WHAT you want it to read, along with memory locations of WHERE you want it to read them.

Again, INT 16h Func=00h returns the key the user pressed in AL as far as I can remember... It all depends on the function/interface being used, but common places for passing information are: memory, registers and stack (which is memory).
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 1

Author Comment

by:Corey_819
ID: 12009380
Thank aib_42 you gave me some ideas on what I need to do. Thanks for taking the time to help :)
0
 
LVL 7

Expert Comment

by:aib_42
ID: 12013046
I am sorry I couldn't be of any more help. Instruction decoding is a rather hard thing (which I'm inexperienced at), and we all know that even commercial debuggers don't get it right all the time.
0
 
LVL 7

Expert Comment

by:aib_42
ID: 12013056
Umm, ignore that last post. What it basically said is, "it's 7:20 in the morning and my mind has stopped working."
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question