News:

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

doesnt really make sense....

Started by zowow, August 25, 2005, 06:46:30 PM

Previous topic - Next topic

zowow

hi guys. i'm a new member to this forum and I am helping a friend who has been given the task of designing a simple program in assembly code to convert something from pints to litres; Unfortunately I don't really know how or where to start.

the 8086 code set is defined as:

adc   Add with carry flag
add   Add two numbers
and   Bitwise logical AND
call   Call procedure or function
cbw   Convert byte to word (signed)
cli   Clear interrupt flag (disable interrupts)
cwd   Convert word to doubleword (signed)
cmp   Compare two operands
dec   Decrement by 1
div   Unsigned divide
idiv   Signed divide
imul   Signed multiply
in   Input (read) from port
inc   Increment by 1
int   Call to interrupt procedure
iret   Interrupt return
j??   Jump if ?? condition met
jmp   Unconditional jump
lea   Load effective address offset
mov   Move data
mul   Unsigned multiply
neg   Two's complement negate
nop   No operation
not   One's complement negate
or   Bitwise logical OR
out   Output (write) to port
pop   Pop word from stack
popf   Pop flags from stack
push   Push word onto stack
pushf   Push flags onto stack
ret   Return from procedure or function
sal   Bitwise arithmetic left shift (same as shl)
sar   Bitwise arithmetic right shift (signed)
sbb   Subtract with borrow
shl   Bitwise left shift (same as sal)
shr   Bitwise right shift (unsigned)
sti   Set interrupt flag (enable interrupts)
sub   Subtract two numbers
test   Bitwise logical compare
xor   Bitwise logical XOR

Now i did do some of this type of thing years ago but i am struggling and i think i need a few pointers. I take it the computer needs to do this process:

1.take the conversion factor (0.57) and convert it into binary and place it into one of the index registers.
2.take the input number say the number of pints, convert to binary, and put that into another register
3.perform somekind of division and put that number into another memory location
4.convert the answer back into decimal and output.

Am I getting the right idea or am i totally lost? It seems really simple at first but its confusing me. I do not necessarily want to know the exact answer, i'm more interested in working out how to arrive at it. Any explanations would be gratefully recieved. My email is zowow@hotmail.com or you could reply here. Hope You Can Help! It's one of those problems that will really annoy me if i dont work it out.
Thanks guys.

GregL

zowow,

Sounds like your friend has a homework assignment.

You will want to use floating-point math.

1. Get the number of pints from the input and store in a string.
2. Convert the string to a floating-point variable (REAL4, REAL8 or REAL10).
3. Load the number of pints into the FPU from the floating-point variable (use FLD).
4. Load the conversion factor into the FPU from a floating-point variable (use FLD).
5. Multiply (use FMUL) it will pop the FPU stack.
6. Store the number of liters to a floating-point variable (use FSTP) it will pop the FPU stack.
    The FPU stack should be clear at this point.
7. Convert the number of liters from the floating-point variable to a string.
8. Display the string to the screen.

I would give you a code example, but it sure sounds like homework.

Here is some good reference material on using the FPU: Simply FPU



AeroASM

However 8086 does not have an FPU...

Integer division is done with the div instruction. If you want a/b, then:

put a in eax
use the instruction div b
result in eax.

div works only with registers and memory, not constants.

gabor

Aero pal!

Quote
However 8086 does not have an FPU...

A 8086 does not have eax or ebx either! :))


I tried to recommend to use fixed point aritmethic, but at the end I got into a dead end, because as I know there is no 32 bit muliplication for 8086 CPUs...
Using 16bit numbers is really poor.
How big numbers do you need? What range are them in? Integer part and fraction part?

Example:
You need numbers between 0 and 10 only, and the fractions are in 10^(-4). (0.0001 is the smallest representable number)
Such numbers can be squeezed into 16bit...

Greets,Gábor