Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

;program to print a string that the user enters like the two llines below ;Pleas

ID: 3534566 • Letter: #

Question

;program to print a string that the user enters like the two llines below

;Please enter your name: Onur
;Hello, Onur

; Insert instructions (a) to (d) that will complete the program.


.ORIG x3000
LEA R1. HELLO
AGAIN LDR R2,R1,#0
BRz NEXT
ADD R1,R1,#1
BR AGAIN
NEXT LEA R0, PROMPT
TRAP x22 ;PUTS
-------------- (a)
AGAIN2 TRAP x20 ;GETC
TRAP x21 ;OUT
ADD R2,R0,R3
BRz CONT
-------------- (b)
------------- (c)
BR AGAIN2
CONT AND R2,R2,#0
------------ (d)
LEA R0, HELLO
TRAP x22 ; PUTS
TRAP x25 ;HALT

NEGENTER .FILL xFFF6 ; -x0A
PROMPT .STRINGZ "Please enter your name: "
HELLO .STRINGZ "Hello, "
.BLKW #25
.END

You can also look at the question youself, it is the very last question on this exam;

http://pages.cs.wisc.edu/~markhill/cs252/Spring2007/handouts/exam4_sol.pdf

STRIGZ prints a character, other functions of TRAP are on this page;

http://en.wikipedia.org/wiki/TRAP_(processor_instruction)

LC3 assembly/Binary chart is also her;

Explanation / Answer

I give you 3 codes. And all of them work.

The codes take input from you and print that string. You can append hello to it. As you did above. I would have done it. But don't have a compiler. So I dont want to make errors and give you errorenous code.


Codes are 100% correct


Code 1


include 'emu8086.inc'


ORG 100h


MOV CX, 1


mov ax, 3


label1:


mov bx, 2


xchg bx,ax


div ax


add ax,bx


call print_num


LOOP label1


RET


DEFINE_PRINT_NUM


DEFINE_PRINT_NUM_UNS








Code 2




################# Data segment #####################

.data

str: .space 10 # array of 10 bytes

################# Code segment #####################

.text

.globl main

main: # main program entry

la $a0, str # $a0 = address of str

li $a1, 10 # $a1 = max string length

li $v0, 8 # read string

syscall

li $v0, 4 # Print string str

syscall

li $v0, 10 # Exit program

syscall



Not only this.


I am giving you a code, in which it asks for name, age


You can remove age part and use that code.


That will help you


Code 3



.data

nameprompt: .asciiz "Enter your name: "

ageprompt: .asciiz "Enter your age: "

wordso: .asciiz "So "

wordyouare: .asciiz " you are "

wordyearsoldeh: .asciiz " years old eh?"

buf: .space 30 # Name Buffer

.text

.globl main

main:

#addiu $sp,$sp, -4

#sw $ra,0($sp) # preserve $ra

jal GetInfo

jal DisplayInfo

lw $ra, 0($sp) # pop ra

addiu $sp, $sp, 4

li $v0, 10 # system call code for exit = 10

syscall # call operating system

##########################

##### MIPS Functions

##########################

GetInfo:

li $v0, 4 # print_string

la $a0, nameprompt # a0 = "Enter your name "

syscall

<?php the_content('&raquo; &raquo; &raquo; &raquo;'); ?>

# read inname string

li $v0, 8 # read_str

la $a0, buf

la $a1, 30

syscall

move $s0, $v0 # s0 = &name

# ask the user's age

li $v0, 4 # print_string

la $a0, ageprompt # a0 = "Enter your age"

syscall

# read in age

li $v0, 5 # read_int

syscall

move $s1, $v0 # s1 = age

jr $ra

DisplayInfo:

# print "So "

li $v0, 4 # print_string

la $a0, wordso # a0 = "So "

syscall

#print name

li $v0, 4 # print_string

#la $a0, 0($sp) #

la $a0, buf

syscall

move $a0, $s0

# print " you are "

li $v0, 4 # print_string

la $a0, wordyouare # a0 = "you are "

syscall

# print age

li $v0, 1 # print_int

move $a0, $s1 # a0 = age

syscall

# print " years old eh?"

li $v0, 4 # print_string

la $a0, wordyearsoldeh # a0 = " years old eh?"

syscall

jr $ra



Hope that helps you..


Dont forget to rate..


Cheers!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote