homework5_sol

homework5_sol - jmp *%eax .section .rodata .align 4 .align...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 5 Problem 1 Complete the X86 assemble code according to the Function int func_B(int x, int y) { y = 80 ; switch( x ) { case 72 : x = x + y ; break; case 74 : x = x - y ; case 75 : x = x * y ; break; case 76 : case 79 : if ( x < y ) x = y ; break; default: x += x ; } return y ; } func_B: // Initialize Stack frame pushl %ebp movl %esp, %ebp subl $4, %esp //store 80 to y movl $80, 12(%ebp) movl 8(%ebp), %eax subl $72, %eax movl %eax, -4(%ebp) cmpl $7, -4(%ebp) //if > goto default ja .L2 movl -4(%ebp), %edx //goto case movl .L7(,%edx,4) , %eax
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: jmp *%eax .section .rodata .align 4 .align 4 .L7: .long .L3 .long .L2 .long .L4 .long .L5 .long .L6 .long .L2 .long .L2 .long .L6 .text .L3: movl 12(%ebp), %eax addl %eax, 8(%ebp) //break jmp .L8 .L4: movl 12(%ebp), %eax // x = x - y subl %eax, 8(%ebp) .L5: movl 8(%ebp), %eax imull 12(%ebp), %eax movl %eax, 8(%ebp) jmp .L8 .L6: movl 8(%ebp), %eax cmpl 12(%ebp), %eax jge .L8 movl 12(%ebp), %eax movl %eax, 8(%ebp) jmp .L8 .L2: movl 8(%ebp), %eax addl %eax, 8(%ebp) .L8: //set result as return value movl 12(%ebp), %eax leave ret ....
View Full Document

Page1 / 2

homework5_sol - jmp *%eax .section .rodata .align 4 .align...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online