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

C Program: Document every line 1. Think of a c function int ReturnGreatest int *

ID: 3598862 • Letter: C

Question

C Program: Document every line

1. Think of a c function int ReturnGreatest int *n1, int *n2, int *n3) which takes 3 address pointer and return the greatest number of all the three. Write a C code and then use the compiler to generate its corresponding assembly code for this function (assuming for a 32-bit machine). (15) Make sure your code has appropriate comments, so that it would be understandable 2. Have a look at the assembly code and explain what is being done here. Instead of explaining verbosely, you can write a c code to explain that (hints: this function is returning some value). Assignment method. pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp), %edx movl 4(%ebp),%esi movl (%ecx),%eax xorl %eax, %eax and/ %esi, %eax movl-41%ebp),%ebx movl %ebp,%esp popl %ebp re

Explanation / Answer

basmain proc far

assume cs:cseg,ds:cseg,ss:nothing,es:nothing

push ds ; save ds

xor ax,ax

mov ds,ax ; ds=0

mov si,4f2h ; dos communications area

mov ax,es ; get psp seg

mov [si],ax ; save psp in dos comm area

pop ds ; restore ds

mov si,80h ; point to command line

mov ch,0

mov cl,[si] ; get length of command line

jcxz p025 ; it's zero

p010: inc si

mov al,[si] ; get char from command line

cmp al,'/' ; is it a slash?

jnz p020 ; no

mov ax,[si+1] ; get next 2 chars

cmp ax,':M' ; is it M: ?

jz p030 ; yes

cmp ax,':m' ; is it m: ?

jz p030 ; yes