The goal of this lab is to familiarize you with assembly language programs. You
ID: 3812668 • Letter: T
Question
The goal of this lab is to familiarize you with assembly language programs. You need to work in teams of 2 to complete this lab.
You need to modify the class example "Copying a String" at the end of the Assembly Language II lecture. You need to modify the example program so it copies from the end of the source string and stores the copied values starting at the beginning of the target (destination) string. The target string should be the reversed version of the source string. For example, the program should take a source string of "RCGC CSC203" and create a target string "302CSC CGCR". You cannot use the stack push and pop operations for this assignment. The purpose of this assignment is to learn how to use a loop and arrays.
Requirements:
Display source string on the screen.
Use a LOOP instruction to build a loop used to copy a character at a time from the source to the destination.
Finally, display the target (destination) string on the screen.
Place a comment at the beginning of your program with your names and date completed.
Explanation / Answer
Code:
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.rdata
.align 2
$LC0:
.ascii "RCGC CSC203"
.align 2
$LC1:
.ascii "The string is:"
.align 2
$LC2:
.ascii "
The reverse string is:"
.text
.align 2
.globl main
$LFB0 = .
.set nomips16
.ent main
.type main, @function
main:
.frame $fp,48,$31 # vars= 8, regs= 3/0, args= 16, gp= 8
.mask 0xc0010000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-48
$LCFI0:
sw $31,44($sp)
$LCFI1:
sw $fp,40($sp)
movz $31,$31,$0
$LCFI2:
sw $16,36($sp)
$LCFI3:
move $fp,$sp
$LCFI4:
.cprestore 16
lw $2,%got($LC0)($28)
nop
addiu $2,$2,%lo($LC0)
sw $2,28($fp)
lw $2,%got($LC1)($28)
nop
addiu $4,$2,%lo($LC1)
lw $2,%call16(puts)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $0,24($fp)
b $L2
nop
$L3:
lw $2,24($fp)
lw $3,28($fp)
nop
addu $2,$3,$2
lb $2,0($2)
nop
move $4,$2
lw $2,%call16(putchar)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
$L2:
lw $16,24($fp)
lw $4,28($fp)
lw $2,%call16(strlen)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$2,-1
sltu $2,$2,$16
xori $2,$2,0x1
andi $2,$2,0x00ff
bne $2,$0,$L3
nop
lw $2,%got($LC2)($28)
nop
addiu $4,$2,%lo($LC2)
lw $2,%call16(puts)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $4,28($fp)
lw $2,%call16(strlen)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$2,-1
sw $2,24($fp)
b $L4
nop
$L5:
lw $2,24($fp)
lw $3,28($fp)
nop
addu $2,$3,$2
lb $2,0($2)
nop
move $4,$2
lw $2,%call16(putchar)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $2,24($fp)
nop
addiu $2,$2,-1
sw $2,24($fp)
$L4:
lw $2,24($fp)
nop
nor $2,$0,$2
srl $2,$2,31
andi $2,$2,0x00ff
bne $2,$0,$L5
nop
move $2,$0
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
lw $16,36($sp)
addiu $sp,$sp,48
j $31
nop
.set macro
.set reorder
.end main
$LFE0:
.size main, .-main
.section .eh_frame,"aw",@progbits
$Lframe1:
.4byte $LECIE1-$LSCIE1
$LSCIE1:
.4byte 0x0
.byte 0x1
.globl __gxx_personality_v0
.ascii "zP"
.uleb128 0x1
.sleb128 -4
.byte 0x1f
.uleb128 0x5
.byte 0x0
.4byte __gxx_personality_v0
.byte 0xc
.uleb128 0x1d
.uleb128 0x0
.align 2
$LECIE1:
$LSFDE1:
.4byte $LEFDE1-$LASFDE1
$LASFDE1:
.4byte $LASFDE1-$Lframe1
.4byte $LFB0
.4byte $LFE0-$LFB0
.uleb128 0x0
.byte 0x4
.4byte $LCFI0-$LFB0
.byte 0xe
.uleb128 0x30
.byte 0x4
.4byte $LCFI3-$LCFI0
.byte 0x11
.uleb128 0x10
.sleb128 3
.byte 0x11
.uleb128 0x1e
.sleb128 2
.byte 0x11
.uleb128 0x1f
.sleb128 1
.byte 0x4
.4byte $LCFI4-$LCFI3
.byte 0xd
.uleb128 0x1e
.align 2
$LEFDE1:
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
Output:
The String is:
RCGC CSC203
The reverse string is:
302CSC CGCR
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.