Translate C code into MIPS program that will: 1) read in an image name (gray lev
ID: 3802847 • Letter: T
Question
Translate C code into MIPS program that will:
1) read in an image name (gray level image in binary format), the number of rows and the number of columns
2) using a function read in the image (.bin file, see code below)
3) using a function compute its histogram (see code below)
4) using a function then output the histogram (see expected output below)
You can assume the image size is no larger than 500x500.
Expected output at end of page
END OF FILE histogram.c
Expected output:
Thank you and please comment if you need any more info
Explanation / Answer
Pre-requisite: Read the instruction set of MIPS first.
Following MIPS code for main program:
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.rdata
.align 2
$LC0:
.ascii "Please enter a pgm image file name: "
.align 2
$LC1:
.ascii "%s"
.align 2
$LC2:
.ascii "Image with %d rows and %d columns.
"
.align 2
$LC3:
.ascii "The histogram of image "%s" is
"
.align 2
$LC4:
.ascii "%d "
.text
.align 2
.globl main
$LFB0 = .
.set nomips16
.ent main
.type main, @function
main:
.frame $fp,1328,$31 # vars= 1296, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-1328
$LCFI0:
sw $31,1324($sp)
$LCFI1:
sw $fp,1320($sp)
movz $31,$31,$0
$LCFI2:
move $fp,$sp
$LCFI3:
.cprestore 16
sw $4,1328($fp)
sw $5,1332($fp)
lw $2,%got($LC0)($28)
nop
addiu $4,$2,%lo($LC0)
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$fp,40
lw $3,%got($LC1)($28)
nop
addiu $4,$3,%lo($LC1)
move $5,$2
lw $2,%call16(scanf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $4,$fp,40
addiu $3,$fp,32
addiu $2,$fp,36
move $5,$3
move $6,$2
lw $2,%call16(_Z8read_pgmPcPiS0_)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $2,28($fp)
lw $2,28($fp)
nop
beq $2,$0,$L2
nop
lw $3,32($fp)
lw $2,36($fp)
lw $4,%got($LC2)($28)
nop
addiu $4,$4,%lo($LC2)
move $5,$3
move $6,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $5,32($fp)
lw $3,36($fp)
addiu $2,$fp,296
lw $4,28($fp)
move $6,$3
move $7,$2
lw $2,%call16(_Z9histogramPhiiPi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$fp,40
lw $3,%got($LC3)($28)
nop
addiu $4,$3,%lo($LC3)
move $5,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $0,24($fp)
b $L3
nop
$L4:
lw $2,24($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,272($2)
lw $3,%got($LC4)($28)
nop
addiu $4,$3,%lo($LC4)
move $5,$2
lw $2,%call16(printf)($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)
$L3:
lw $2,24($fp)
nop
slt $2,$2,256
andi $2,$2,0x00ff
bne $2,$0,$L4
nop
li $4,10 # 0xa
lw $2,%call16(putchar)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
$L2:
move $2,$0
move $sp,$fp
lw $31,1324($sp)
lw $fp,1320($sp)
addiu $sp,$sp,1328
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 0x530
.byte 0x4
.4byte $LCFI2-$LCFI0
.byte 0x11
.uleb128 0x1e
.sleb128 2
.byte 0x11
.uleb128 0x1f
.sleb128 1
.byte 0x4
.4byte $LCFI3-$LCFI2
.byte 0xd
.uleb128 0x1e
.align 2
$LEFDE1:
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
Likewise, program can be coded for the other two functions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.