Results 1 to 5 of 5

Thread: Assembly, got skill?

  1. #1
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default Assembly, got skill?

    Create a MIPS function readchar that reads a single character from the secondary UART on our backend machines. An incomplete main-hw10-q2.S is provided for you. Rename it to main.S for this question. This main.S calls readchar function, for which you will implement at the end of the file to input characters from the second UART, and echoes them back using sendchar until an EOF character is seen.


    Here is the code I was given (Am require to use) Anyone know what this question is asking me to do? and is anyone capable of doing this? I honestly hit a brick wall


    Code:
    #include <mips.h>
    .data
    
    FMT:	.string		"the char is %c\r\n"
    
    .text
    .globl main
    
    main:
            /* Function prolog.             */
            /* Sets up environment for user program to execute.             */
            addiu   sp, sp, -32  /* Make room on Stack for O/S values.  */
            sw      ra, 28(sp)   /* Store O/S return address on Stack.  */
            /* Start of your program.       */
    
    	li	s0, 0xB8000400//THR
    	
    loop:	
    	jal	readchar
    	li	t0, 4
    	beq 	v0, t0, done
    	move 	s2, v0
    	la	a0, FMT
    	move	a1, v0
    	jal 	kprintf
    //	move	a0, s2
    //	jal	sendchar
    	b	loop
    	
    
                    
                    
            
    done:   /* End of your program.         */
            /* Function epilogue.           */
            /* Restores the environment from the O/S. */
            lw      ra, 28(sp)  /* Restore O/S return address.              */
            addiu   sp, sp, 32  /* Restore O/S stack pointer.               */
            li      v0, 0       /* Return value of 0 (normal exit).         */
            jr      ra          /* Return to Operating System.              */
    
    
    //reads character
    //implement the readchar function below
    readchar:
    Help would glaadlyyy be appreciated, and or compensated if wanted.
    Last edited by [XoL]; 12-12-2013 at 01:45 AM.

  2. #2
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default

    wait dumb comment, hmm thank you! will look into this more
    Last edited by [XoL]; 12-12-2013 at 01:44 AM.




    Anti-Leech Movement Prevent Leeching Spread the word
    Insanity 60 Days (Killer workout)
    XoL Blog (Workouts/RS/Misc)

  3. #3
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default

    Code:
    #include <mips.h>
    .data
    
    FMT:	.string		"the char is %c\r\n"
    
    .text
    .globl main
    
    main:
            /* Function prolog.             */
            /* Sets up environment for user program to execute.             */
            addiu   sp, sp, -32  /* Make room on Stack for O/S values.  */
            sw      ra, 28(sp)   /* Store O/S return address on Stack.  */
            /* Start of your program.       */
    
    	li	s0, 0xB8000400//THR
    	
    loop:	
    	jal	readchar
    	li	t0, 4
    	beq 	v0, t0, done
    	move 	s2, v0
    	la	a0, FMT
    	move	a1, v0
    	jal 	kprintf
    //	move	a0, s2
    //	jal	sendchar
    	b	loop
    	
    
                    
                    
            
    done:   /* End of your program.         */
            /* Function epilogue.           */
            /* Restores the environment from the O/S. */
            lw      ra, 28(sp)  /* Restore O/S return address.              */
            addiu   sp, sp, 32  /* Restore O/S stack pointer.               */
            li      v0, 0       /* Return value of 0 (normal exit).         */
            jr      ra          /* Return to Operating System.              */
    
    
    //reads character
    //implement the readchar function below
    readchar:
    myloop:
    lb t0,5(s0)
    		andi t0,t0,0b00100000
    		beq t0, zero, myloop
    		sb a0, 0(a0)
    		jr ra

    ***
    How about that? keep getting a compile error though on the loop




    Anti-Leech Movement Prevent Leeching Spread the word
    Insanity 60 Days (Killer workout)
    XoL Blog (Workouts/RS/Misc)

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

    Default

    Quote Originally Posted by [XoL] View Post
    ***
    How about that? keep getting a compile error though on the loop
    Your code looks like it will work.

    Currently:
    s0 holds the address of the port or memory location we want to read from.
    v0 will hold our result.
    ASM Code:
    li  $s0, 0xB8000400   #access register/UART port.

    So:
    ASM Code:
    readchar:
        lbu  $t0, 0xB8000400 #load the port/mapped io. maybe not needed because s0 contains 0xB8000400 aka port address
     try:
        lb   $t1, 5($t0)     #control register. t0 can be replaced with $s0. t1 will tell us if it is ok to read from the port or not.
        andi $t1, $t1, 0x1   #is it ok for us to read? yes or no? 1 or 0? Might have to be: 0b00100000 like you have above.
        beq  $t1, $0, try    #if we cannot read from the port, try again until the port is not busy.
        lb   $v0, $0($t0)    #read the character into v0.
        jr   $ra

    Another example:
    ASM Code:
    readint:
            lui  $t0, 0xB8000400 #maybe not needed but s0 contains 0xB8000400 aka port address.
       waitl:
            lw   $t1, 0($t0)    #control register. $t0 can be replaced with $s0.
            andi $t1, $t1, 0x1  #t1 will store whether or not we can read from the port. Might have to be: 0b00100000 like you have above.
            beq  $t1, $0, waitl #keep looping until we successfully read a character from the port.
            lw   $v0, 4($t0)    #read our character into the #v0 register.
            jr   $ra


    I think your code may work as well but I don't have a mips assembler readily available to test and I'm writing in Notepad (no notepad++) atm either.
    Last edited by Brandon; 12-12-2013 at 02:45 AM.
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default

    Got it:

    li t0, 0xB8000400
    myloop: lb t1, 5(t0)
    andi t1, t1, 0x1
    beq t1, zero, myloop
    lb v0, 0(t0)
    jr ra

    Edit: FML, Wish I refreshed more often didn't know you wrote it out! lol well my code is basically identical, thanks brandon really appreciate it!




    Anti-Leech Movement Prevent Leeching Spread the word
    Insanity 60 Days (Killer workout)
    XoL Blog (Workouts/RS/Misc)

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
  •