Help in this code F=(x+y*4b^3)/2 and F=(x^2/y^2)*3

Started by egsonas, May 03, 2008, 05:56:05 PM

Previous topic - Next topic

egsonas

Hi everyone,

in Assembler i'm new one.
Our dull teacher  :dazzled: pushes us to hard and wants that we knew everything and done work. Codes statement follows like this: "Calculate two functions:  F=(x+y*4b^3)/2  and  F=(x^2/y^2)*3.   x and y user insert by keyboard. Result save in file."
More over, in the first lesson we looked only one example.
Can anyone help me in my code? Or even anyone done this code before?


Please help.

Thanks in advance.
Egas, beginner programmer

Jimg

Is this supposed to be a 16 bit DOS or 32 bit Windows program?
What do you have so far?
Is it integer or floating point input/computation,output?
Are you using a particular library of routines?
We need a lot more information before we can even begin to help, and you need to show us that you've put a little effort into this already.
This should also have been posted in the campus section, or not at all if you are just begging us to do your homework.

Jimg

QuoteHow to write cube for variable "b" and put in my code line?
You multiply it times itself 3 times.  eg.
   mov ax, 4
   mul b
   mov cx,ax
   mul cx        ; = 4b ^ 2
   mul cx         ; = 4b ^ 3
however, I'm not sure if 4b^3 means   (4b) ^ 3   or   4 * (b ^ 3)    so adjust as desired.
(Also be aware, the result is in DX:AX, so if the user inputs a large number for b, and 4b^3 is greater than 65535 you will have to adjust as needed.

as far as the rest, I haven't done 16 bit interrupt programming in 10 years, so maybe someone else will help.


MichaelW

Assume that rm16 means a 16-bit register or a 16-bit memory variable.

A 16-bit unsigned multiply produces a 32-bit product from two 16-bit multiplicands. The processor expects one of the multiplicands to be AX, and places the product in the DX:AX register pair:

DX:AX = AX * rm16

A 16-bit unsigned divide produces a 16-bit quotient from a 32-bit dividend and a 16-bit divisor. The processor expects the dividend to be the DX:AX register pair, and places the quotient in AX and the remainder in DX:

AX = DX:AX / rm16

Your code in reply #7 is not far off, but you need to calculate x*x second so the result will be in DX:AX for the divide operation. And for this there is no need to zero DX, because as long as x*x produces a 16-bit product DX will be zero.

    mov ax, y
    mul y       ; ax = y*y
    mov cx, ax  ; cx = y*y
    mov ax, x
    mul x       ; ax = x*x
    div cx      ; ax = (x*x)/(Y*Y)
    mov cx, 3
    mul cx      ; ax = (x*x)/(Y*Y) * 3

eschew obfuscation

MichaelW

QuoteWhat is the different between your code and mine?

The biggest difference is that your code is performing the * 3 before performing the divide. Assuming that this is school work, did they teach you nothing about operator precedence and Order of operations? For some values of x and y your code will produce the correct result, but for others it will not. For example, if x = 4 and y = 3, your result will be 5, where the correct result is 3.
eschew obfuscation

MichaelW

div is an integer instruction, so 16/9=1 with a remainder of 7. If you are supposed to generate a floating point result you should be using the FPU, as well as performing the operations in the correct order.
eschew obfuscation

dedndave

i think F=(x+y*4b^3)/2 is F=(x+4yb3)/2 or F=2yb3+x/2
and F=(x^2/y^2)*3 is F=3x2/y2
reminds me of my high school algebra homework - lol