Passing parameters in assembly language irvine Library
Passing parameters in assembly language irvine Library
I'm trying to write a program to calculate the area of a circle by passing parameter. the program prompts a user to enter radius through the main PROC. the are is computed in another procedure say; Area and the results returned in the main PROC. this is done using Irvine32 library. I cant fugure out how to pass parameters. this is what i've done
INCLUDE Irvine32.inc
.data
varx BYTE "Enter radius: "
radius DWORD ?
y DWORD 22d
z DWORD 7d
varz BYTE "The Area of the circle is "
.code
area PROC
mov ecx, eax
mov eax, y
mov ebx, z
mul ecx
mul ecx
div ebx
mov edx, OFFSET varz
call WriteString
call WriteInt
call DumpRegs
ret
area ENDP
main PROC
mov edx, OFFSET varx
call WriteString
call ReadInt
mov ebx, eax
call area
exit
main ENDP
END main
y
z
call area
eax
ebx
ecx
eax+ebx
mul
BTW, as you are using MASM, I can just recommend you this extremely short but informal tutorial: cs.virginia.edu/~evans/cs216/guides/x86.html (many other resources at x86 tag info: stackoverflow.com/tags/x86/info )
– Ped7g
Jun 29 at 11:11
Anyway, to answer your core question "how to pass parameters" the answer is: "any way you wish". When you want your functions to be callable from "outside" by other developers/libraries/OS, it is nice to pick one of possible calling conventions and use it's rules and document that, so then anyone else trying to call your function will know how to pass arguments for it, but as long as only your code is involved, you have full control over arguments passing. In this particular case I don't see any reason why not to use the value which is already in
eax
after ReadInt
, without any copy of it.– Ped7g
Jun 29 at 11:16
eax
ReadInt
Also it is good practice to follow "single responsibility/purpose" while designing procedures, i.e. "calculate_circle_area", it shouldn't display it, just calculate it, and return it for example in
eax
, then you can display it. ... actually reading through your code once more, doesn't it work correctly? Seems a bit redundant and with uninformative/wrong labels, but looks like it may actually calculate the circle area well.– Ped7g
Jun 29 at 11:21
eax
Here at MASM32.com is a short example of PROC/INVOKE.
– zx485
Jun 29 at 15:06
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is
y
andz
? What kind of formula do you want to use to calculate circle area? It looks like you keep randomly adding instructions expecting "something" to happen, instead of having some master plan. But you have the high level of plan described in question... atcall area
you have the radius in botheax
andebx
registers (why in both?), then you move it toecx
immediately and destroyeax+ebx
with y+z... try to watch your code in debugger while single stepping over instructions, and watch values in registers, the basic mov/call things should be easy (mul
is more tricky).– Ped7g
Jun 29 at 11:10