Assembly code programs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • confusedprogrammer
    New Member
    • Sep 2006
    • 12

    Assembly code programs

    1) Write a program to determine the correct admission price to a movie. The price of admission to a movie is $7 for kids (under 12) and $9 for adults. Display the correct admission fee after the user gives you the age for one person.

    Sample Run #1:
    ? 21
    9

    Sample Run #2:
    ? 11
    7

    This is what i have so far... I keep getting a unknown ALU operation. Please Help

    Code:
    INP 26
    LDA 26
    LDB 23
    CMP
    JGT 25
    JLT 24
    
    
    
    PNT 24
    PNT 25
    STP
    
    
    
    
    
    
    
    
    
    
    
    12
    7
    9
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    It is not possible to get an any more platfrm specific language than assembly code (there is machine code but that isn't really a language that is the actual code that runs on the machine).

    Since you have failed to mention the platform you are working on it is anybodys guess what might be valid assembly code.

    Comment

    • confusedprogrammer
      New Member
      • Sep 2006
      • 12

      #3
      Ok, here are the instructions that i can use and they are used on a 32 bit processor.

      STP Stop the program
      LDA Load register A with value from a specified memory location
      LDB Load register B with value from a specified memory location
      STR Store register B value to a specified memory location
      INP Store data input by user to a specified memory location
      PNT Print the value stored in a specified memory location to the screen
      JLT Jump if less than (Status register = -1) to a specified memory location
      JGT Jump if greater than (Status register = 1) to a specified memory location
      JEQ Jump if equal (Status register = 0) to a specified memory location
      JMP Unconditional jump to a specified memory location
      CMP Compare register A to register B and set Status Register value
      ADD Add (register A + register cool.gif and store sum in register B
      SUB Subtract (register A - register cool.gif and store difference in register B
      MUL Multiply (register A * register cool.gif and store product in register B
      DIV Divide for quotient (register A/register cool.gif and store quotient in register B
      MOD Divide for remainder (register A/register cool.gif and store remainder in register B

      Using 32 memory locations starting at 0 - 31

      Comment

      • confusedprogrammer
        New Member
        • Sep 2006
        • 12

        #4
        Our assembly language instructions have two parts:
        The operation code specifies the operation the computer is to carry out (add, compare, etc)
        An address that allows the instruction to refer to a location in main memory
        The CPU runs each instruction in the program, starting with instruction 0, using the fetch-decode-execute cycle.

        Comment

        • D_C
          Contributor
          • Jun 2006
          • 293

          #5
          Code:
          INP 26
          LDA 26
          LDB 23
          CMP
          JLT 25 // jump if under 12
          PNT 25 // print 9 (12 or older)
          JMP // don't print 7 though
          PNT 25 //JLT here (print 7 for under 12)
          STP // JMP HERE
          ...
          12
          7
          9

          Comment

          • kevin russ
            New Member
            • Aug 2011
            • 1

            #6
            I run your code but it does not work correctly. What I am mising? What is on line 10? Thanks

            Comment

            Working...