Help with simple assembly Program

Discussion in 'Assembly Language Programming (ALP) Forum' started by namasteall2000, Jan 22, 2010.

  1. namasteall2000

    namasteall2000 New Member

    Joined:
    Jan 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello - I am new to assembly language and just started to learn- I have a question - I have to get input(string, integer and double) from the user and store and print it on screen - but for some reason my code is showing weird o/p - double/string doesn't work.

    Could somone guide me please?

    #####################################################################
    # Test Program:
    ####################################################################
    .data
    prompt: .asciiz "\n Please Input an Integer value = "
    prompt1: .asciiz "\n Please Input a Double value = "
    prompt2: .asciiz "\n Please Input a Float value = "
    prompt3: .asciiz "\n Please Input a String value = "
    result: .asciiz " The sum of the integers NEW from 1 to N is "
    result1: .asciiz " You have enter : "
    bye: .asciiz "\n **** Have a good day ****"
    .globl main
    .text

    main:

    #Printing a String

    li $v0, 4 # system call code for Print String
    la $a0, prompt3 # load address of prompt into $a0
    syscall # print the prompt message

    li $v0, 5 # system call code for Read Integer
    syscall # reads the value into $v0

    li $v0, 4 # system call code for Print String
    la $a0, result1 # load address of message into $a0
    syscall # print the string

    #lw $a0, $v0
    li $v0, 1 # system call code for Print Integer
    syscall # print sum of integers

    #print a newline
    la $a0, newline
    li $v0, 4
    syscall




    #Printing an Integer
    li $v0, 4 # system call code for Print String
    la $a0, prompt # load address of prompt into $a0
    syscall # print the prompt message

    li $v0, 5 # system call code for Read Integer
    syscall # reads the value into $v0

    li $v0, 4 # system call code for Print String
    la $a0, result1 # load address of message into $a0
    syscall # print the string

    #lw $a0, $v0
    li $v0, 1 # system call code for Print Integer
    syscall # print sum of integers


    #print a newline
    la $a0, newline
    li $v0, 4
    syscall




    #Printing a double Value

    li $v0, 4 # system call code for Print String
    la $a0, prompt1 # load address of prompt into $a0
    syscall # print the prompt message

    li $v0, 5 # system call code for Read Integer
    syscall # reads the value into $v0

    li $v0, 4 # system call code for Print String
    la $a0, result1 # load address of message into $a0
    syscall # print the string

    #lw $a0, $v0
    li $v0, 3 # system call code for Print Double
    syscall # print sum of integers

    #print a newline
    la $a0, newline
    li $v0, 4
    syscall


    end:
    li $v0, 4 # system call code for Print String
    la $a0, bye # load address of msg. into $a0
    syscall # print the string

    li $v0, 10 # terminate program run and
    syscall # return control to system
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    read and store a string

    Code:
    .data
    S: .space [COLOR=DarkRed]20[/COLOR] #20 characters
    ...........
        la $a0, S        #store input string into S
        li $a1,[COLOR=DarkRed]20[/COLOR]       
        li $v0,8
        syscall
    .............
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice