IE 332 - Homework #1 Due: Sept 23, 11:59pm Read Carefully. Important! As outlined in the course syllabus this homework is worth 7% of your final grade. The maximum attainable mark on this homework is...

Instructions in file A1


IE 332 - Homework #1 Due: Sept 23, 11:59pm Read Carefully. Important! As outlined in the course syllabus this homework is worth 7% of your final grade. The maximum attainable mark on this homework is 140. As was also outlined in the syllabus, there is a zero tolerance policy for any form of academic misconduct. The assignment can be done individually or in pairs. By electronically uploading this assignment to Blackboard you acknowledge these statements and accept any repercussions if in any violation of ANY Purdue Academic Misconduct policies. You must upload your homework on time for it to be graded. No late assignments will be accepted. Only the last uploaded version of your assignment will be graded. NOTE: You should aim to submit no later than 30 minutes before the deadline, as there could be last minute network tra�c that would cause your assignment to be late, resulting in a grade of zero. When submitting your assignment it is assumed that every student considers the below checklist, as there are grading consequences otherwise (e.g., not submitting a cover sheet is an automatic grade of ZERO). ⇤ Attach a cover sheet (see Blackboard) as the first page of your submission. ⇤ Submit page i of this assignment as the second page of your submission. ⇤ Your solutions have style (see Q1 in the assignment). ⇤ All of your solutions (program code, etc.) are included in the submission. ⇤ All of your source code is included as requested (.R, etc.). ⇤ You have not included any screen shots, photos, etc. (plots from R should be intermediately saved as .png files). ⇤ All math notation and expressions are created using an equation editor (no pictures, handwritten solutions, etc.). ⇤ If using Word or other text processor, convert the output to .pdf and ensure that it does not contain any aesthetic or other errors. Submit only the pdf version. ⇤ If using LATEX, the source code is separately submitted in a .zip file. If using LATEX correctly, there is a 7 point bonus. Failure to submit the source code voids potential bonus. ⇤ If submitting with a partner, BOTH of you have uploaded the SAME assignment before the due date. ⇤ Watch videos on creating pseudocode if you need a refresher or quick reference to the idea. These are good starter videos: www.youtube.com/watch?v=4jLO0vXPktU www.youtube.com/watch?v=yGvfltxHKUU Page i of i https://www.youtube.com/watch?v=4jLO0vXPktU https://www.youtube.com/watch?v=yGvfltxHKUU Kirti Kirti Kirti HW 1 Q1 - Q7 IE 332 Homework #1 Due: Sept 23 2019 1. (0 points) These are style points meant to enforce the skill of communicating technical information in a precise, concise and easily interpretable way. At the discretion of the TA (who should be grading this “hard”), you are penalized for (a) using poor grammar/spelling, (b) disorganized presentation of solutions (including organizing your code into functions, as appropriate), (c) not commenting well your source code, (d) not using meaningful variable names in your code. The presumption is that you should never do any of these things, and so doing them will cost addition points (up to -10). Your goal is to get 0/0 on this question. Unless otherwise noted, the assignment should have margins between 0.5 and 0.75 inches wide, with font size 11 or 12pt (10-11pt for code), sub/superscripts, figure and plot captions excluded, but should be clearly legible. Clearly label each question. If a question requires more than 40% of the page to answer, then that is the only answer on that page. If multiple pages are required, this rule applies to the last of those pages. 2. This question is meant to reinforce your understanding of how a CPU executes program code by focusing on the low-level instructions it executes, versus higher-level instructions you would use in a programming language such as R. You will use the hypothetical assembly language outlined below in Table 1, in addition to 10 registers referred to by $r0, . . . ,$r10, and system RAM as needed. instruction meaning example add reg1, reg2, reg3 reg1 = reg2 + reg3 add $r0, $r1, $r2 sub reg1, reg2, reg3 reg1 = reg2� reg3 sub $r0, $r1, $r2 div reg1, reg2, reg3 reg1 = reg2/reg3 div $r0, $r1, $r2 mul reg1, reg2, reg3 reg1 = reg2 ⇤ reg3 mul $r0, $r1, $r2 muli reg1, reg2, x reg1 = reg2 ⇤ x, where x is some integer mul $r0, $r1, 4 addi reg1, reg2, x reg1 = reg2 + x, where x is some integer addi $r0, $r1, 5 subi reg1, reg2, x reg1 = reg2� x, where x is some integer subi $r0, $r1, 5 divr reg1, reg2, x reg1 = reg2/x, where x is real, truncates result divr $r0, $r1, 2 mov reg1, reg2 reg1 = reg2 mov $r0, $r1 label: create a reference label in the code main: name: .type, value create .type variable in RAM where name = value var1: .word 5 lw reg, RAM source move word from RAM to a register lw $r4, var1 sw reg, RAM source move word from register to RAM sw $r4,var1 la reg, RAM source move address of RAM to a register la $r4 var1 sa reg, RAM source move address in register to RAM sa $r4,var1 b label jump to a label in the program b main beq reg1,reg2,label jump to label if reg1 = reg2 beq $r0,$r1,main blt reg1,reg2,label jump to label if reg1 < reg2="" blt="" $r0,$r1,main="" bgt="" reg1,reg2,label="" jump="" to="" label="" if="" reg1=""> reg2 bgt $r0,$r1,main bqe reg1,reg2,label jump to label if reg1 � reg2 bqe $r0,$r1,main ble reg1,reg2,label jump to label if reg1  reg2 ble $r0,$r1,main bne reg1,reg2,label jump to label if reg1 6= reg2 bne $r0,$r1,main print reg print contents of register to screen print $r0 prints reg print string pointed to in register to screen prints $r0 read reg get keyboard input (after ENTER pressed); store in reg read $r0 done end of program Table 1: Hypothetical assembly language Kirti *NOTE: for lw if RAM source is an integer instead of a memory address, or reg1 and/or reg2 in beq, blt, bgt, bge,ble, bne, then it will be automatically interpreted as such. For instance, lw $r1, 4, will be an equivalent instruction to setting $r1=4. Also, potential variable types include .word (for integers or floats), .bit (for bits), .asciiz (for strings/character arrays - noting that each character has an associated bit pattern and can be interpreted as an integer as well). Furthermore, a sequence of comma separated integers is accepted as valid input, allowing you to create integer arrays, e.g., arr: .asciiz 10,13,12. Arrays are indexed from 1, and accessing a value from an array is done by referring to the RAM source as array name[index] (e.g., if loading an array value, use lw $r1, A[1] where A is the array name). The size of the array is stored at position 0, (e.g. A[0]). Ex. computing the first n Fibonacci numbers (Fn = Fn�1 + Fn�2 for n > 0, F1 = 1 and F2 = 1): string1: .asciiz “The result is: ” value: .word 0 main: read $r9 ble $r9, 0, end lw $r0, value addi $r0, $r0, 1 beq $r9, 1, end mov $r2, $r0 mov $r1, $r2 lw $r8, 1 loop: add $r0, $r1, $r2 mov $r2, $r1 mov $r1, $r0 addi $r8, $r8, 1 beq $r9, $r8, end b loop end: sw $r0, value la $r7, strin1 prints $r7 print $r0 done (a) (14 points) Create an assembly program using the above language for the following C program. Make your solution as concise (fewest number of lines) as possible. When submitting your results show a table with two columns: (1) the original C program, (2) your assembly code. You can increase the page margins or reduce font size to 10pt, if required to improve readability. You can ignore lines 1 and 2 concerning include statements. 1 #inc lude

2 #inc lude

3 4 double c a l c u l a t e var i ance ( double ⇤ my array , s i z e t len , double ave ) { 5 double x=0, var i ance =0; 6 7 f o r ( i n t i = 0 ; i < l="" en="" ;="" i++)="" {="" 8="" x="x" +="" (my="" array="" [="" i="" ]="" �="" ave="" )="" ⇤="" (my="" array="" [="" i="" ]="" �="" ave="" )="" ;="" 9="" }="" 10="" var="" iance="x" l="" en="" ;="" 11="" 12="" re="" turn="" var="" iance="" ;="" 13="" }="" ie="" 332="" homework="" #1="" page="" 2="" of="" 7="" kirti="" 14="" 15="" double="" c="" a="" l="" c="" u="" l="" a="" t="" e="" average="" (="" double="" ⇤="" my="" array="" ,="" s="" i="" z="" e="" t="" l="" en="" )="" {="" 16="" double="" sum="0," average="0;" 17="" 18="" f="" o="" r="" (="" i="" n="" t="" i="0" ;="" i="">< l="" en="" ;="" i++){="" 19="" sum="sum" +="" my="" array="" [="" i="" ]="" ;="" 20="" }="" 21="" 22="" average="sum/" len="" ;="" 23="" 24="" re="" turn="" average="" ;="" 25="" }="" 26="" 27="" i="" n="" t="" main="" (="" )="" {="" 28="" double="" my="" array="" [="" ]="{11" ,="" 22="" ,="" 33="" ,="" 44="" ,="" 55="" ,="" 66="" ,="" 77="" ,="" 88="" ,="" 99="" ,="" 111}="" ;="" 29="" double="" ave="0," var="0;" 30="" i="" n="" t="" l="" en="0;" 31="" 32="" l="" en="s" i="" z="" e="" o="" f="" (my="" array="" )="" s="" i="" z="" e="" o="" f="" (my="" array="" [="" 0="" ]="" )="" ;="" 33="" ave="c" a="" l="" c="" u="" l="" a="" t="" e="" average="" (my="" array="" ,="" l="" en="" )="" ;="" 34="" var="c" a="" l="" c="" u="" l="" a="" t="" e="" var="" i="" ance="" (my="" array="" ,="" len="" ,="" ave="" )="" ;="" 35="" 36="" p="" r="" i="" n="" t="" f="" (="" ”my="" array="" var="" iance="\" t="" %f="" \n”="" ,="" var="" )="" ;="" 37="" 38="" re="" turn="" 0="" ;="" 39="" }="" (b)="" (3="" points)="" provide="" pseudocode="" for="" the="" given="" c="" program.="" be="" mindful="" of="" the="" balance="" between="" too="" little="" and="" too="" much="" detail!="" (c)="" (3="" points)="" convert="" the="" given="" c="" code="" to="" equivalent="" but="" fewest="" lines="" of="" r="" code="" to="" print="" the="" same="" result.="" use="" existing="" r="" function(s)="" or="" you="" will="" lose="" points.="" do="" not="" line-by-line="" convert="" the="" c="" code!="" (d)="" (4="" points)="" state="" the="" tight="" bound="" for="" the="" worst="" case="">

Sep 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here