-
Notifications
You must be signed in to change notification settings - Fork 0
/
sp1.S
48 lines (48 loc) · 1009 Bytes
/
sp1.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
/* Benjamin J Miller bjmillr2 */
/* Ted Culbertson tculber2 */
/* Grant Everett geveret2 */
/* Liuren Wang lwang108 */
/* Olivia Mitchell ozmitch2 */
/* Branden Youssef byousse2 */
/* Sindhu Gudala gudala2 */
/* save registers */
pushl %ecx
pushl %edx
pushl %ebx
/* get parameters */
/* 16 for three on stack and return address */
movl $16(%esp), %edx # for arg
movl $20(%esp), %eax # for bitmask
/* init registers */
xorl %ecx, %ecx # for i counter
xorl %ebx, %ebx # for bit
incl %ebx # sets bit to 1
/* for loop */
for_loop:
cmpl $32, %ecx # compare for for loop
jnb return
testl %ebx, %ecx # sets flags
jne bit_shift
pushl %eax
pushl %edx
call *jump_table(, %ecx, 4) # array lookup
/* does this set return value */
addl 4, %esp # move stack pointer down
/* restore registers */
popl %eax
popl %ebx
popl %edx
popl %ecx
ret
bit_shift:
shll $1, %ebx
incl %ecx
jmp for_loop
return:
/* restore registers */
popl %ebx
popl %edx
popl %ecx
xorl %eax, %eax
ret