首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代做program、代写c/c++编程设计
项目预算:
开发周期:
发布时间:
要求地区:
Lab 6 Structs, Function Pointers, Multiply & Divide
Contents
Lab 6 Structs, Function Pointers, Multiply & Divide .....................................................................................1
Version 1 .......................................................................................................................................................2
Dates.............................................................................................................................................................2
Early by 11:58 PM, Thursday 11-April-2024 .........................................................................................2
On Time by 11:58 PM, Friday 12-April-2024.........................................................................................2
Late until 11:58 PM, Saturday 13-April-2024........................................................................................2
Introduction ..................................................................................................................................................2
The Struct and the Jump Table .....................................................................................................................2
The ops.s file .................................................................................................................................................3
4 Functions................................................................................................................................................3
Plus............................................................................................................................................................3
Left Shift....................................................................................................................................................3
Times.........................................................................................................................................................3
Divide ........................................................................................................................................................3
Warp-up for ops........................................................................................................................................3
The do_op.s file.............................................................................................................................................3
Shims.............................................................................................................................................................4
Output...........................................................................................................................................................4
ops_test ....................................................................................................................................................4
lab6 ...........................................................................................................................................................5
bonus ........................................................................................................................................................5
Bonus +2 points – do not try until you have working code turned in ..........................................................5
Register Allocation........................................................................................................................................6
Required Stuff – There’s new stuff here.......................................................................................................6
Comments.....................................................................................................................................................6
Readme .........................................................................................................................................................6
Submission....................................................................................................................................................7
Machine Generated Code.............................................................................................................................7
Version 1
Dates
Early by 11:58 PM, Thursday 11-April-2024
On Time by 11:58 PM, Friday 12-April-2024
Late until 11:58 PM, Saturday 13-April-2024
Introduction
This lab involves:
• Function pointers in assembler
• Structs
• Shift by a variable amount
• Divide
• Multiply
You will write two files of assembler code, ops.s and do_op.s for this lab. For the bonus, you would
write search.s as well. The supplied zipfile has everything else you need, but the makefile will have to be
customized with your zip target and your name.
The Struct and the Jump Table
The following code is in lab6.c:
struct Operation {
int result; // offset is zero
char printable; // offset is 4
short operation; // offset is 6
int a,b; // offsets are 8 and 12
}; // the struct is 16B long
typedef int (*mathOp)(int a, int b);
mathOp table[] = { plus, left_shift, times, divide};
struct Operation ops_table[] = {
{0, '+', 0, 4, 16},
{0, '<', 1, 16, 4},
{0, '*', 2, 16, 4},
{0, '/', 3, 16, 4}
};
The ops.s file
4 Functions
This file will contain 4 very short functions (plus, left_shift, times, and divide). They will return the
values listed below
• a+b
• a<
• a*b
• a/b
Plus
The plus function is extremely simple, get the sum of %rdi and %rsi into %rax.
Left Shift
To left shift by a variable amount, the number of places to shift needs to wind up in %cl. Put the value
you want shifted in eax and then use (shift, arithmetic, left, long)
sall %cl, %eax
Times
For times, use imul. This version of multiply is pretty straightforward.
Divide
Because of the way the original chip was severely limited, divide has very particular idiosyncrasies. The
thing you will divide starts out in RAX or a smaller version of it. Then we do magic on it to extend it,
which will trash RDX (or a smaller subset of it). Then we can divide by any of the other registers.
Assume that our multiply was on assembler longs and not quads, which means EAX holds our result. If
ECX holds the value we are dividing by, we would get the code below. It can be in any of the caller saved
other than EAX or EDX. That would yield:
cltd # the magic conversion that trashes edx
idivl %ecx # divide eax by ecx, result is in eax
Warp-up for ops
That’s it. 4 really short functions that only use the parameter registers and rax. Use the ops_test target
to test them. Write them one at a time and comment out ones you don’t want tested. (Read the
supplied code in ops_test.c. The ops_test code uses a special shim to make sure that your 4 function
don’t mess up,.
Even if you have no clue about structs, you can start on these four right away.
The do_op.s file
The do_op function goes in this file. It feeds a couple of pesky prints and also calls the appropriate math
function. It does not call them directly. (Go read the supplied lab6.c file). The function gets passed:
• A pointer to a struct Operation
• A table of function pointers
This is what the code should do:
int do_op( struct Operation *op, mathOp table[])
{
printf("%d %c %d = ...\n", op->a, op->printable, op->b);
int rval = table[op->operation](op->a, op->b);
op->result = rval;
printf("...%d %c %d = %d\n\n", op->a, op->printable, op->b,
op->result);
return rval;
}
1. First is stack housekeeping – this function makes many calls, you know what registers it needs
2. Next, deal with print (your code will call print, not printf). Grab the parameters that print needs
from memory. Use the offsets to figure where to get the values. Be very careful about sizes.
Remember that printf wants anything smaller than an int to be promoted to an int.
3. Next is the indirect call. Get the operation member out of the struct, converting the C short to a
C long (assembler quad) so that you can use it to get into the array of pointers. Then get the
two parameters out of the struct and into the correct parameter registers. Then make the
indirect call. Be sure to stash the value returned someplace safe.
4. Then deal with the second printf (your code will call print), which should be easy since it is very
much like the first one.
5. Lastly, deal with he return value and unwinding the stack.
There are only 2 complicated parts here, dealing with struct members and the indirect call. A glance at
the favorite opcode slide deck might be in order, it shows how to make indirect calls. You have an array
of 8-byte pointers in memory, one of them is the correct one to call.
Shims
The driver code deals with most of the shims. Your code has to call print and not printf. Your lab 6
won’t have a shim between do_op and the math operation functions it calls, but ops_test will have a
shim making sure that the math operation functions are clean.
Output
Your output should match these.
ops_test
[kirby.249@cse-sl2 lab6]$ ops_test
16 + 4 = ...
...16 + 4 = 20
16 < 4 = ...
...16 < 4 = 256
16 * 4 = ...
...16 * 4 = 64
16 / 4 = ...
...16 / 4 = 4
[kirby.249@cse-sl2 lab6]$
lab6
[kirby.249@cse-sl2 lab6]$ lab6
Lab 6 is searching...
16 / 4 = ...
...16 / 4 = 4
16 * 4 = ...
...16 * 4 = 64
16 < 4 = ...
...16 < 4 = 256
4 + 16 = ...
...4 + 16 = 20
The largest result comes from: 16 < 4 = 256
[kirby.249@cse-sl2 lab6]$
bonus
BONUS is searching...
16 / 4 = ...
...16 / 4 = 4
16 * 4 = ...
...16 * 4 = 64
16 < 4 = ...
...16 < 4 = 256
4 + 16 = ...
...4 + 16 = 20
The largest result comes from: 16 < 4 = 256
[kirby.249@cse-sl2 lab6]$
Bonus +2 points – do not try until you have working code turned in
Do search as an assembler function and put it in a file called “search.s” as seen in the makefile for the
bonus target. Use the provided C code to see what search has to do.
Register Allocation
Register allocation policy is graded.
SOme of the required functions are leaf-level and the some are not. This guides your register allocation
policy.
You really do want a firm grasp on register allocation before you take the final exam, so work it out here.
Before you write any code, figure out how many “variables” you will need and assign them to registers
of the appropriate type.
Required Stuff – There’s new stuff here
All of your functions must create a stack frame upon entry and tear it down upon exit.
Different from lab 5:
Near the top of every function, create in comments your pocket guide to the registers. Each register
used in the function must have a comment telling what that register means. For example:
# rax is both a subscript and return value at the same time.
In your comments you should refer to the registers not by name but by what they mean.
Comments
Comment your code. Comments should say things that are not obvious from the code. In assembler
you could easily have something to say for every line of code. You could easily have more comment lines
than code lines. Comment what each register holds. Comment about how the operation has a higher
level meaning. Try to avid comments that say the exact same thing as the code – this might get you
points off.
Near the top of every function, write out in comments what every register the code uses will mean. This
is your pocket guide to the registers when writing the function.
Put your name and the assignment number in your initial comments. Also add the statement that says
that you wrote all of the code in the file (see below). Or you can forget it and get a zero on the lab.
Readme
As always, create a text README file, and submit it with your code. All labs require a readme file.
Include:
• Your name
• If it qualifies for bonus points
• Hours worked on the lab
• Short description of any concerns, interesting problems, or discoveries encountered. General
comments about the lab are welcome.
Submission
No surprises here. Your zip file needs:
• A readme file
• All of your .s files
• Makefile, modified to add a zip target and your name
• The supplied files needed to make all targets build
Be sure that the zip target in the makefile self-tests by making ops_test and lab6 (and possibly bonus)
from the contents of the zip file. Any zip file that fails to build gets a zero. Any makefile that doesn’t
self-test the zip is marked late regardless of when it was turned in.
Be sure to add this text to ALL of your .s files:
# BY SUBMITTING THIS FILE AS PART OF MY LAB ASSIGNMENT, I CERTIFY THAT
# ALL OF THE CODE FOUND WITHIN THIS FILE WAS CREATED BY ME WITH NO
# ASSISTANCE FROM ANY PERSON OTHER THAN THE INSTRUCTOR OF THIS COURSE
# OR ONE OF OUR UNDERGRADUATE GRADERS. I WROTE THIS CODE BY HAND,
# IT IS NOT MACHINE GENRATED OR TAKEN FROM MACHINE GENERATED CODE.
If you omit a required file, you get zero points.
If you fail to add the above comment you get zero points
If the make command as given generates any warnings or errors you get zero points
Every file you hand edit needs your name in it.
Machine Generated Code
Do not use –S with gcc to generate any assembler from C code. Do not use any AI such as github copilot
to do this lab. Doing so is academic conduct.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
cis432代做、代写python/java程...
2024-05-04
eeen3007j代写、c++程序设计代...
2024-05-04
代写data程序、代做c/c++, jav...
2024-05-04
comp2006代做、代写c++程序语言
2024-05-04
comp26020代做、java/c++设计编...
2024-05-04
csci251 advanced programming...
2024-05-03
cs 6290: high-performance co...
2024-05-03
assignment 2: executing and ...
2024-05-03
ecse427/comp310 programmin...
2024-05-03
cs 452 (fall 22): operating...
2024-05-03
comp9414 23t2 assignment 2 ...
2024-05-03
dpst1091 23t1 assignment 2 ...
2024-05-03
program代做、代写python设计编...
2024-05-03
热点标签
finm8007
comp2006
comp26020
comp1721
eeen3007j
cis432
csci251
comp5125m
com398sust
32022
mth6158
comp328
finn41615
2024
mec302
mgmt3004
mgt7158
com160
as.640.440
econ3016
finm7405
econ7021
fin600
infs4205/7205
mktg2510-
f27sb
csse2310/csse7231
rv32i
eecs 113
comp1117b
cs 412
comp 315
econ7300
comp2017
ecs 116
fit5046
com6511
comp30024
acs341
econ1020
isys3014
acc408
comp1047
csc 256
cs 6347
finm7008
comp34212
csmde21
estr2520
comp285/comp220
mds5130/iba6205
finc6010
is3s665
busi2194
125.785
iom209
msin0041
econ339
cmt218
mast10007
comp5349
ecx2953/ecx5953
bios706
comp3310
mth6150
comp30027
comp20005
eec286
busi2211
bff2401
fnce90046
visu2001
mang6554
finc6001
125785
data423-24s1
engi 1331
fint2100
(520|600).666
can202
cs 61b
mast20029
info20003
stat512
econ3208
cmpsc311
engg1340
ecmt1010
fit5216
basc0003
ee3121
acct2002
comp5313
busi2131
ise529
elec372/472
csit940/csit440
cenv6141
comp3027/comp3927
ftec5580
comp1433
msci223
mark203
en3098
eden1000
ece6483
econ4410
mats16302
cs 6476
com6521
comp222
comp3211
comp10002
csc1002
chc6186
cs 161
comp27112
comp282
swen20003
comm1190
elec9764
acfi3308
acct7101
fin6035
comp2048
geog0163
comp2013
coen 146
dts101tc
sehh2042
comp30023
comp4880/8880
cs 455
07
stat0045.
fil-30023
celen085
psyc40005
math40082
are271
comp9311
ee5311
imse2113
comp 2322
acct2102
fnd109
int102
is3s664
is6153
data4000
accfin5034
fit5212
cs536-s24
fit5225
ecos3006
mes202tc
finc5001
stat3061
csc171
cs1b
7ssmm712
bu.450.760
cs170
comp3411
swen90004
cpt206
comp5313/comp4313—large
bl5611
kxo206
comp532
elec207
kxo151
cs 2820
cpt108
math2319
dts204tc
qm222
comp2511
ccs599
infs1001
mat2355
eeee4123
25721
ifn647
pols0010
hpm 573
qbus6860
comp9417
csci 1100
stat0023
cse340
comp2003j
cs 2550
cs360
fin 3080
ierg 4080
cs6238
cit 594
finm7406
hw6
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!