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

Please write comments next to code to its easy to understand. Assembly language

ID: 3870840 • Letter: P

Question

Please write comments next to code to its easy to understand. Assembly language is used for this code and its from Computer organization

You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for the expression: without using any intrinsic multiplication instructions. More formally, write MIPS assembly code that accepts four positive integers a, b, c, and d as input parameters. The code shall execute in MARS to prompt the user to enter four positive integers represented in decimal, each separated by the Enter key. The program shall calculate f= (AC3-3C2+8D2-4B) and g=(A2C+B2D2) using your own self-written multiplication routine. The program will then output f in decimal and binary, using syscall routines for each output. Note: To receive credit, no multiplication, no division, and no shift instructions shall be used. Namely, none of mul, mul.d, mul.s, mulo, mulou, mult, multu, mulu, div, divu, rem, sll, sllv, sra, srav, srl, srlv) or else a zero score will result. Thus, it is necessary to compose your own multiplication technique. In addition, use of a loop is required for credit to realize the multiplication code

Explanation / Answer

.file "dtob.c"
.text
.globl f
.type f, @function
f:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl %edx, -12(%rbp)
movl %ecx, -16(%rbp)
movl -12(%rbp), %eax
imull -12(%rbp), %eax
imull -12(%rbp), %eax
imull -4(%rbp), %eax
movl %eax, %ecx
movl -12(%rbp), %eax
imull -12(%rbp), %eax
movl %eax, %edx
movl %edx, %eax
addl %eax, %eax
addl %edx, %eax
negl %eax
leal (%rcx,%rax), %edx
movl -16(%rbp), %eax
imull -16(%rbp), %eax
imull -8(%rbp), %eax
leal (%rdx,%rax), %ecx
movl -8(%rbp), %edx
movl $0, %eax
subl %edx, %eax
sall $2, %eax
addl %ecx, %eax
cltq
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size f, .-f
.globl g
.type g, @function
g:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl %edx, -12(%rbp)
movl %ecx, -16(%rbp)
movl -4(%rbp), %eax
imull -4(%rbp), %eax
imull -12(%rbp), %eax
movl %eax, %edx
movl -8(%rbp), %eax
imull -8(%rbp), %eax
movl %eax, %ecx
movl -16(%rbp), %eax
imull -16(%rbp), %eax
imull %ecx, %eax
addl %edx, %eax
cltq
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size g, .-g
.globl dec_to_bin
.type dec_to_bin, @function
dec_to_bin:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movq %rdi, -24(%rbp)
movl $31, -4(%rbp)
jmp .L6
.L7:
movl -4(%rbp), %eax
movq -24(%rbp), %rdx
movl %eax, %ecx
sarq %cl, %rdx
movq %rdx, %rax
andl $1, %eax
addl $48, %eax
movl %eax, %edi
call putchar
subl $1, -4(%rbp)
.L6:
cmpl $0, -4(%rbp)
jns .L7
movl $10, %edi
call putchar
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE2:
.size dec_to_bin, .-dec_to_bin
.section .rodata
.LC0:
.string "Enter a,b,c and d vlaues : "
.LC1:
.string "%d%d%d%d"
.LC2:
.string "f_ten = %ld "
.LC3:
.string "f_two = "
.LC4:
.string "g_ten = %ld "
.LC5:
.string "g_two = "
.text
.globl main
.type main, @function
main:
.LFB3:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movl $.LC0, %edi
call puts
leaq -20(%rbp), %rsi
leaq -24(%rbp), %rcx
leaq -28(%rbp), %rdx
leaq -32(%rbp), %rax
movq %rsi, %r8
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
movl -20(%rbp), %ecx
movl -24(%rbp), %edx
movl -28(%rbp), %esi
movl -32(%rbp), %eax
movl %eax, %edi
call f
movq %rax, -16(%rbp)
movl -20(%rbp), %ecx
movl -24(%rbp), %edx
movl -28(%rbp), %esi
movl -32(%rbp), %eax
movl %eax, %edi
call g
movq %rax, -8(%rbp)
movq -16(%rbp), %rax
movq %rax, %rsi
movl $.LC2, %edi
movl $0, %eax
call printf
movl $.LC3, %edi
movl $0, %eax
call printf
movq -16(%rbp), %rax
movq %rax, %rdi
call dec_to_bin
movq -8(%rbp), %rax
movq %rax, %rsi
movl $.LC4, %edi
movl $0, %eax
call printf
movl $.LC5, %edi
movl $0, %eax
call printf
movq -8(%rbp), %rax
movq %rax, %rdi
call dec_to_bin
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE3:
.size main, .-main
.ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
.section .note.GNU-stack,"",@progbits