Sum, Saturated | Sum, Modular | Carry (y/n) | Overflow (y/n) | |
---|---|---|---|---|
FEF3 + 99AA | ||||
0007 + 7FFE | ||||
8FFF + 20E0 | ||||
8000 + 8000 |
Hexadecimal | Signed Decimal | IEEE-754 Single Precision (Decimal) |
---|---|---|
49.25 | ||
-1.5 × 2-131 | ||
FFFFFFCC | ||
0CC00000 | ||
100 | ||
-100 |
UTF-32 | UTF-16 | UTF-8 |
---|---|---|
000000CA | ||
000004F5 | ||
0000E188 | ||
0010E6F2 |
A B C | X Y ---------+------ 0 0 0 | 0 1 0 0 1 | 0 0 0 1 0 | 1 0 0 1 1 | 1 0 1 0 0 | 0 1 1 0 1 | 1 1 1 1 0 | 1 0 1 1 1 | 1 0
Design two logic circuits for this function, one using AND, OR and NOT gates only, and one using NAND gates only.
$ piano_keys A 27.5000 A# 29.1352 B 30.8677 C 32.7032 C# 34.6478 D 36.7081 D# 38.8909 . . . A# 3729.3101 B 3951.0664 C 4186.0090
$ piano_scales F# F# major: F# G# A# B C# D# E# F# minor: F# G# A B C# D E
"doghouse"
and 3
will return
"housedog"
. More examples:
rotate("doghouse", 0) ⇒ "doghouse" rotate("doghouse", 1) ⇒ "oghoused" rotate("doghouse", 2) ⇒ "ghousedo" rotate("doghouse", 3) ⇒ "housedog" rotate("doghouse", 4) ⇒ "ousedogh" rotate("doghouse", 5) ⇒ "usedogho"
ho3 = hohoho
.
(Hint: Be very careful about the '\0' at the end.)
substring("snoopdog", 2, 6) ==> "oopd" substring("snoopdog", 32, 456) ==> "" substring("snoopdog", -5, 2) ==> "sn"
#include <stdio.h> int main(int argc, char** argv) { if (argc != 2) { printf("Exactly one argument required\n"); return 1; } FILE* f = fopen(argv[1]); if (f == NULL) { printf("File does not exist\n"); return 2; } // Okay you do the rest.....
gcd(x, y) = (y == 0) ? x : gcd(y, x mod y)
double f(double a, double b, double c);
double logBaseThreeOf(double x);
ecx
by 5 with a single
lea
instruction.
x
pointing
to three consecutive signed doublewords in memory. Write assembly language
fragments to place in eax the median of the three values (1) using
no conditional jumps, and (2) using conditional jumps.
int spfft(int a, int b, int* c, int d) { if (&b < c) return a / b / *c % d; else return d * *c; }
paddb mm0,mm1
mm0 would be __________________________
paddw mm0,mm1
mm0 would be __________________________
paddsb mm0,mm1
mm0 would be __________________________
paddusb mm0,mm1
mm0 would be __________________________
psubsw mm0,mm1
mm0 would be __________________________
void replaceAllValuesWithTheirSquareRoots(float a[], int length);
using the SQRTPS
instruction. That is, you should do the
square root computations four at a time.
PMAXUB
instruction:
void f(char* a, char* b) { int i; for (i = 0; i < 8; i++) if (a[i] < b[i]) a[i] = b[i]; }
void run(char* s, int n) { // Executes the n bytes of machine code starting at address s, // then gracefully returns to the caller. For example, if the string // "\x53\x66\x68\x68\x69\x89\xE1\x31\xC0\x40\x89\xC3\x40\x89\xC2\xD1 // \xE0\xCD\x80\x44\x44\x5B" were passed in, the function should // write the string "hi" to standard output. ... }
MOVAPS
and
MOVDQA
?
cmovg
.
mystery: cdq xor eax, edx sub eax, edx ret
Explain why it works.
fyl2x
and fldl2t
instructions.
double f(double a, double b);
sub %ebx, %eax cltd and %eax, %edx add %edx, %ebx
The cltd instruction is the same as the two instruction sequence:
mov %eax, %edx sar $31, %edx
add esi, dword [edi+eax+8]
xor esp, dword [edi+esp+8]
and eax, 2
sbb edi, ecx
sar dword [ebx+ebp+20], 1
xor eax, ebx xor ebx, eax xor eax, ebx
Show the machine language for it.
cdq shr edx, 22 add eax, edx sar eax, 10
lock repnz shufpd xmm6, [esi*4+200], -2
.
0f 02 => opcode for LAR 75 (01110101) => modr/m, 01:reg+disp8, 110:spare is 6 => esi, 101: ebp 00 => 8 bit displacement with value 0 Result => LAR esi, [ebp+0]
#include <stdio.h> int (*f)() = "\xb0\x64\x0f\xb6\xc0\xc3"; int main() {printf("%d\n", f());}
On an x86, What does this program do and why?
For example
00000000 9d cc 23 00 90 87 33 11 34 56 c1 dd 9c aa 9b bc 00000010 11 23 5b 6b 89 89 89 89 32 2a ca fe e4 4e 32 10 00000020 2e e6
The name of the file should come from the command line, and the output should be written to stdout.
int 80h
. Define
a C function that invokes the exit system call with return code 0, using
embedded machine language, like this:
void (*exit)() = "........";
You fill in the string. Hand assemble the code that invokes the exit system call. Make sure you don't have any zeros in the machine code. Does it really matter if the machine code does have zeros?
31 c9 8d 41 08 bb 13 00 00 00 cd 80
31 c0 89 c3 40 cd 80 64 6f 67 00
. When it was loaded into memory, however,
I noticed it was 31 c9 8d 41 08 bb 93 80 04 08 cd 80
31 c0 89 c3 40 cd 80 64 6f 67 00
. Explain the difference. What memory
location was the program loaded at? For extra credit, what
program is this?
31 DB 43 89 D8 C1 E0 01 89 C2 C1 E0 01 B9 16 00
00 00 CD 80 EB EA 79 0A
. When it was loaded into memory, however,
I noticed it was 31 DB 43 89 D8 C1 E0 01 89 C2 C1 E0 01 B9 8A 80
04 08 CD 80 EB EA 79 0A
. Explain the difference. What memory
location was the program loaded at? For extra credit, what
program is this?
mystery: call helper ret helper: mov eax, [esp] sub eax, 5 ret
Note that superficial, obvious observations like "it calls a function that returns 5 less than the value on the stack top" will earn you zero points. Tell me intent of the code, then tell me a much simpler way to do that.