PDA

View Full Version : Need help with computer science homework



Google
10-08-2014, 08:37 PM
If anyone can help me here would be greatly appreciated, 3 problems here I am not sure how to do.

1) When the following statement is executed, what happens to the memory location storing the variable named firstNumber?


Display “Enter your first number:"
Input firstNumber


2) Write a Display statement that will do the following:
Display the variable “gradeAverage” with an appropriate label describing the value being displayed for the end user.

3) Write an assignment statement that will store the results of adding three numbers together in a variable called numberSum. What are two other things that could be to the right of the “=” in an assignment statement?

Brandon
10-12-2014, 04:54 PM
What language is this? Looks similar to Basic/QBasic with a mash of FoxPro..

If this is assembly, you're going to have to explain more and the interpreter/assembler being used.. What are the details of the subject (what are you currently learning in CS.. specific topic)?

As for what truly happens at the lowest possible level of any language when you ask for input:

The variable is loaded into a register or pushed directly onto the stack or the "effective address" is loaded (LEA instruction). When input is gathered, it writes to that address OR to the intermediary.

Ex (32-bit assembly with CRT):


push variable ;memory location of variable.
push format
call [scanf]
add esp, 0x08

;OR:

push esp ;variable is already on the stack being pushed onto the stack.
push format
call [scanf]
pop esp
add esp, 0x04

;OR:
xor eax, eax
mov eax, variable ;intermediary is eax. //variable is moved into a register. Register is then pushed onto the stack.
push eax
push format
call [scanf]
pop eax
add esp, 0x04

;OR:
LEA eax, [EBP - 4] ;stack allocated variables. Variable is in stack allocated memory. Memory location is simply loaded.
LEA edx, [EBP - 8]
push eax ;variable
push edx ;format
call [scanf]
pop edx
pop eax


In 16-bit assembly, it's the same thing but you won't be using scanf.. you'd be using interupts:


mov ah, 1h
int 21h


It all depends on the language and how the optimizer decides to work or how you decide to do it.. But this is just what happens at the lowest level..

We need to know what you're working with (what language as well) in order to answer your questions properly.. Just saying "Help me" isn't enough. Can't do anything with that. Throwing a bunch of assembly at you, isn't my idea of fun. Well.. it is fun but meh.. doesn't help. Give more details for better help.

Frement
10-12-2014, 05:15 PM
Brandon, I love when someone asks for help with their computer science homework and you just shove some ASM down their throat! Brilliant :p