In this problem, you will write a LC-3 assembly code that removes blank spaces f
ID: 3817527 • Letter: I
Question
In this problem, you will write a LC-3 assembly code that removes blank spaces from a string. Assume that the string starts at memory location 0x4000, and is terminated by a ‘’ character (ASCII value = 0). Your program should store the modified string in the memory location starting at 0x4100. You do not need to modify the original string stored at 0x4000. You can assume that the original string at 0x4000 will always be less than 100 characters in length, and it will always start with a letter (A-Z, lowercase or uppercase possible).
Note: If the modified string has 7 characters, and the original string has 15 characters, the last 8 characters of your modified string should be all ‘’ (ASCII value = 0).
For example: If the original string at 0x4000 was “aa 12 d e f ”, the modified string at 0x4100 after your program completes execution should be “aa12def ” . Note that the original string has 8 blank space characters, and the modified string has 8 extra “” in the end. Your code should start at memory location 0x3000.
Explanation / Answer
$LFB0 = .
main:
addiu $sp,$sp,-80
sw $31,76($sp)
sw $fp,72($sp)
move $fp,$sp
lui $28,%hi(__gnu_local_gp)
addiu $28,$28,%lo(__gnu_local_gp)
lw $2,%got(__stack_chk_guard)($28)
lw $2,0($2)
sw $2,68($fp)
sw $0,32($fp)
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
lw $2,%call16(puts)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
addiu $2,$fp,36
move $4,$2
lw $2,%call16(gets)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
sw $0,28($fp)
lw $2,28($fp)
addiu $3,$fp,72
addu $2,$3,$2
lb $2,-36($2)
beq $2,$0,$L2
nop
lw $2,28($fp)
addiu $3,$fp,72
addu $2,$3,$2
lb $3,-36($2)
li $2,32 # 0x20
beq $3,$2,$L3
nop
lw $2,32($fp)
addiu $3,$2,1
sw $3,32($fp)
lw $3,28($fp)
addiu $4,$fp,72
addu $3,$4,$3
lb $3,-36($3)
addiu $4,$fp,72
addu $2,$4,$2
sb $3,-36($2)
lw $2,28($fp)
addiu $2,$2,1
sw $2,28($fp)
b $L4
nop
lw $2,32($fp)
addiu $3,$fp,72
addu $2,$3,$2
sb $0,-36($2)
addiu $2,$fp,36
move $5,$2
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
lw $2,%call16(printf)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
move $2,$0
lw $3,%got(__stack_chk_guard)($28)
lw $4,68($fp)
lw $3,0($3)
beq $4,$3,$L6
nop
lw $2,%call16(__stack_chk_fail)($28)
move $25,$2
1: jalr $25
nop
move $sp,$fp
lw $31,76($sp)
lw $fp,72($sp)
addiu $sp,$sp,80
j $31
nop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.