help - 2((length*width)+(length*height)+(height*width))

[b][red]This message was edited by RodeoBurnz at 2002-10-2 18:17:1[/red][/b][hr]
I'm trying to write code that will satisfy the formula: 2((length*width)+(length*height)+(height*width)). It doesn't seem to be working correctly. I think its because each value is used at least twice and the memory allocation for the multiplication replaces the original value of what is stored. Please someone help. Here's the code:

[code]
.CODE ; start of main program code
_start:
Prompt: output prompt1 ; prompt for width
input value,16 ; read ASCII characters
atod value ; convert to integer
mov ebx,eax ; width( store in EBX )

output prompt2 ; prompt for height
input value,16 ; read ASCII characters
atod value ; convert to integer
mov ecx,eax ; height( store in ECX )

output prompt3 ; prompt for length
input value,16 ; read ASCII characters
atod value ; convert to integer
mov edx,eax ; length( store in EDX )

imul ebx,ecx ; width * height( store in EBX )
imul ecx,edx ; height * length( store in ECX )
imul edx,ebx ; length * width( store in EDX )
add ebx,ecx ; (w*h) + (h*l), store in EBX
add ebx,edx ; EBX + (l*w), store in EBX
mov eax,ebx ; copy EBX to EAX
add eax,eax ; 2((w*h)+(l*w)+(h*l))

dtoa area,eax ; convert to ASCII characters
output answer ; output label and result

INVOKE ExitProcess, 0 ; exit with return code 0
[code]

Thank you!

Comments

  • [b][red]This message was edited by Josh Code at 2002-10-3 15:30:53[/red][/b][hr]

    : I'm trying to write code that will satisfy the formula: 2((length*width)+(length*height)+(height*width)). It doesn't seem to be working correctly. I think its because each value is used at least twice and the memory allocation for the multiplication replaces the original value of what is stored. Please someone help. Here's the code:
    :
    : [code]
    : .CODE ; start of main program code
    : _start:
    : Prompt: output prompt1 ; prompt for width
    : input value,16 ; read ASCII characters
    : atod value ; convert to integer
    : mov ebx,eax ; width( store in EBX )
    :
    : output prompt2 ; prompt for height
    : input value,16 ; read ASCII characters
    : atod value ; convert to integer
    : mov ecx,eax ; height( store in ECX )
    :
    : output prompt3 ; prompt for length
    : input value,16 ; read ASCII characters
    : atod value ; convert to integer
    : mov edx,eax ; length( store in EDX )
    :
    : imul ebx,ecx ; EBX = width * height
    [b]from now on, EBX is not the width, it is width*height.
    I think this is the source of your problem. Try storing this w*h value in EAX and don't change EBX.[/b]
    : imul ecx,edx ; ECX = height * length
    : imul edx,ebx ; [b]EDX = width * (width * height)[/b]
    ;[red]length * width( store in EDX )[b]incorrect[/b][/red]
    : add ebx,ecx ; (w*h) + (h*l), store in EBX
    : add ebx,edx ; EBX = (w*h) + (h*l)+ [b](w*w*h)[/b]
    : mov eax,ebx ; copy EBX to EAX
    : add eax,eax ; 2((w*h) + (h*l)+(w*w*h))
    :
    : dtoa area,eax ; convert to ASCII characters
    : output answer ; output label and result
    :
    : INVOKE ExitProcess, 0 ; exit with return code 0
    : [/code]
    :
    : Thank you!
    :

    I think you're right about the values getting replaced.
    You wanted to output:
    2((length*width)+(length*height)+(height*width))

    I think you are actually outputting: 2((w*h) + (h*l)+(w*w*h))





  • How can I store width*height in EAX, width is already in EBX so the instruction operand for multiplying w*h is "imul ebx,ecx" which will automatically store the product in EBX. Can I make a copy of EBX first before multiplying it? Please help. Thank you for reply.


    2((length*width)+(length*height)+(height*width)).
    : :
    : : [code]
    : : .CODE ; start of main program code
    : : _start:
    : : Prompt: output prompt1 ; prompt for width
    : : input value,16 ; read ASCII characters
    : : atod value ; convert to integer
    : : mov ebx,eax ; width( store in EBX )
    : :
    : : output prompt2 ; prompt for height
    : : input value,16 ; read ASCII characters
    : : atod value ; convert to integer
    : : mov ecx,eax ; height( store in ECX )
    : :
    : : output prompt3 ; prompt for length
    : : input value,16 ; read ASCII characters
    : : atod value ; convert to integer
    : : mov edx,eax ; length( store in EDX )
    : :
    : : imul ebx,ecx ; EBX = width * height
    : [b]from now on, EBX is not the width, it is width*height.
    : I think this is the source of your problem. Try storing this w*h value in EAX and don't change EBX.[/b]
    [size=4][blue]HOW DO I STORE W*H IN EAX?[/blue][/size]
    : : imul ecx,edx ; ECX = height * length
    : : imul edx,ebx ; [b]EDX = width * (width * height)[/b]
    : ;[red]length * width( store in EDX )[b]incorrect[/b][/red]
    : : add ebx,ecx ; (w*h) + (h*l), store in EBX
    : : add ebx,edx ; EBX = (w*h) + (h*l)+ [b](w*w*h)[/b]
    : : mov eax,ebx ; copy EBX to EAX
    : : add eax,eax ; 2((w*h) + (h*l)+(w*w*h))
    : :
    : : dtoa area,eax ; convert to ASCII characters
    : : output answer ; output label and result
    : :
    : : INVOKE ExitProcess, 0 ; exit with return code 0
    : : [/code]
    : :
    : : Thank you!
    : :
    :
    : I think you're right about the values getting replaced.
    : You wanted to output:
    : 2((length*width)+(length*height)+(height*width))
    :
    : I think you are actually outputting: 2((w*h) + (h*l)+(w*w*h))
    :
    :
    :
    :
    :
    :

  • [code]
    .CODE ; start of main program code
    _start:
    Prompt: output prompt1 ; prompt for width
    input value,16 ; read ASCII characters
    atod value ; convert to integer
    mov ebx,eax ; width( store in EBX )

    output prompt2 ; prompt for height
    input value,16 ; read ASCII characters
    atod value ; convert to integer
    mov ecx,eax ; height( store in ECX )

    output prompt3 ; prompt for length
    input value,16 ; read ASCII characters
    atod value ; convert to integer
    mov edx,eax ; length( store in EDX )

    mov eax,ebx ; eax = width
    imul eax,ecx ; eax = width * height
    imul ecx,edx ; height * length( store in ECX )
    imul edx,ebx ; length * width( store in EDX )
    add eax,ecx ; eax = (w*h) + (h*l)
    add eax,edx ; EaX=(w*h)+(h*l) + (l*w)
    shl eax,1 ; 2((w*h)+(l*w)+(h*l))
    ; if you wanted to, "add eax,eax" does the same thing as "shl eax,1" but shl is a little more efficient. It is a binary shift to the left by 1 digit. Its the same as multiplying by 2.

    dtoa area,eax ; convert to ASCII characters
    output answer ; output label and result

    INVOKE ExitProcess, 0 ; exit with return code 0

    [/code]
  • Thank you for all your help. It is appreciated. I applaud you!!!

    RodeoBurnz
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories