a:
push #4
mov #5 -> %r0
st %r0 -> [fp]
ld [fp] -> %r0
add %r0, %g1 -> %r0
ret
.globl tmp
s:
ld [fp+12] -> %r0
ld [r0] -> %r0
st %r0 -> tmp
ld [fp+16] -> %r0
ld [r0] -> %r0
ld [fp+12] -> %r1
st %r0 -> [r1]
ld tmp -> %r0
ld [fp+16] -> %r1
st %r0 -> [r1]
ret
s:
ld [fp+12] -> %r0
mov #12 -> %r1
add %r0, %r1 -> %r0
ld [r0] -> %r0
ld [r0] -> %r0
ret
s:
st %r2 -> [sp]--
ld [fp+16] -> %r0 / Step 1
mov #3 -> %r1
mul %r0, %r1 -> %r0
ld [fp+20] -> %r1 / Step 2
mov #5 -> %r2
mul %r1, %r2 -> %r1
add %r0, %r1 -> %r0 / Step 3
mov #4 -> %r1 / Step 4
mul %r0, %r1 -> %r0
ld [fp+12] -> %r1
add %r0, %r1 -> %r0
ld [r0] -> %r0 / Step 5
ld [fp+24] -> %r1 / Step 6
mov #3 -> %r2
sub %r1, %r2 -> %r1
mov #4 -> %r2 / Step 7
mul %r1, %r2 -> %r1
add %r0, %r1 -> %r0
ld [r0] -> %r0 / Step 8
ld ++[sp] -> %r2
ret
For further detail, the following files have main()s in them so that you can run
them under jassem. Each file has its main() in a comment:
main()
{
struct stat buf;
JRB t1, t2, tmp, tmp2;
struct dirent *de;
DIR *d;
d = opendir(".");
if (d == NULL) { perror("opendir ."); exit(1); }
t1 = make_jrb();
for (de = readdir(d); de != NULL; de = readdir(d)) {
if (de->d_name[0] != '.') {
if (stat(de->d_name, &buf) != 0) {
perror(de->d_name);
exit(1);
}
tmp = jrb_find_int(t1, buf.st_mtime);
if (tmp == NULL) {
tmp = jrb_insert_int(t1, buf.st_mtime, new_jval_v((void *) make_jrb()));
}
t2 = (JRB) tmp->val.v;
jrb_insert_str(t2, strdup(de->d_name), JNULL);
}
}
jrb_rtraverse(tmp, t1) {
t2 = (JRB) tmp->val.v;
jrb_traverse(tmp2, t2) {
printf("%s\n", tmp2->key.s);
}
}
}
It's also in exam-q2.c if you'd like to compile it
and run it.
You set the setuid bit of file f with:
UNIX> chmod 04755 f
Part 2: You first write a program that prints out the first line of the file in question. That file's name should be hard-coded into the executable, and that should be an absolute pathname. Then you set the setuid bit of the program using the chmod command above. Finally, you set the permissions of the file to something like 0600 or 0400. Now, when another user runs the program, he/she will assume your identity, and will be able to read the first line of the file.
This cannot be done without the setuid bit, because otherwise you would have to set the permissions of the file to be world readable (0644 or 0444), giving users access to all lines of the file, and not just the first line.
main:
push #8
st %g0 -> [fp]
mtop:
ld stdin -> %r0
st %r0 -> [sp]--
st %g1 -> [sp]--
mov #4 -> %r0
st %r0 -> [sp]--
mov #-4 -> %r0
add %r0, %fp -> %r0
st %r0 -> [sp]--
jsr fread
pop #16
cmp %r0, %g0
ble mbot
ld [fp] -> %r0
add %r0, %g0 -> %r0
st %r0 -> [fp]
b mtop
mbot:
ret
= 202.5 + .65x + 200(x div 4192) microseconds
This is approximatly 202.5 + .6977x microseconds
Procedure 2 differs from Procedure 1 in two ways:
So the final tally is:
= 200.4 + 50.25x microseconds