If i declare my variables under .data they are considered as global variables, how can i declare them locally
@paul I am able to allocate memory but how can i type cast them(such as signed and unsigned int)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Declaration of local variables in assembly code depends on your assembler and it may not support such declarations at all.
Typically, local variables are allocated by moving (decrementing) the stack pointer. Allocation and initialization of a local variable on the stack can be fused together if you use the push instruction, which advances the stack pointer and writes to the stack. Example of this:
As for signed, unsigned and casting, there’s no such thing in assembly. CPUs do exactly what you tell them to. They don’t interpret inputs or outputs, it’s you, the programmer to make that interpretation. And so, if you want to divide two integers as unsigned, you execute
DIVwith the values of the integers and if you want to make a signed division, you do the same with theIDIVinstruction. If you useIDIVon what you think is usigned integers (orDIVon signed integers), the CPU will happily do that for you and the wrong result (or a division overflow exception) will be your problem to deal with. Luckily, addition, subtraction and multiplication of unsigned and 2’s complement signed integers is done in the same way by the CPU for both kinds of integers and you don’t need to do anything special like choosing the right instruction for each kind. Typically, only division and comparison differ between signed and unsigned integers. But again, you take care of this difference explicitly in the code.