Results 1 to 3 of 3

Thread: Need help with computer science homework

  1. #1
    Join Date
    Jan 2012
    Posts
    713
    Mentioned
    3 Post(s)
    Quoted
    9 Post(s)

    Default Need help with computer science homework

    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?
    Code:
    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?

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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):

    ASM Code:
    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:

    ASM Code:
    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.
    Last edited by Brandon; 10-12-2014 at 05:05 PM.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Brandon, I love when someone asks for help with their computer science homework and you just shove some ASM down their throat! Brilliant
    There used to be something meaningful here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •