Test Driven Development in Assembler a little story about growing software from nothing
|
|
|
- Lesley Stafford
- 10 years ago
- Views:
Transcription
1 Test Driven Development in Assembler a little story about growing software from nothing Olve Maudal During the last decade Test-Driven Development has become an established practice for developing software in the industry. All good programmers must have TDD in the toolbox so that they can use it when appropriate. In this session I will demonstrate Test-Driven Development by example, using nothing but assembler language. A 90 minute session ACCU, Oxford, April 2012
2 Disclaimer: This is not meant as a tutorial to learn about assembler programming. For example, I am avoiding all/most of the idioms that experienced assembler programmers use (eg, xor to reset a variable, repeat string operations, proper looping, newer and specialized instructions etc). The reason I do this is partly because I am inexperienced with real assembly programming myself, but mostly because it does not add too much value when demonstrating TDD techniques which is the intention of this presentation. Also, I know already that there are some bugs in the code so use with care! If you want to learn about assembler programming on Intel CPU s and BSD based systems I suggest the following sources:
3
4
5
6
7
8
9
10
11
12
13 LSD *NIX i386 ed, as, ld, make
14 LSD *NIX i386 ed, as, ld, make
15 Hello, world!
16 Hello, world! kernel: int 80h section.data greeting db 'Hello, world!', 0xa section.text global start start: push dword 14 push dword greeting push dword 1 mov eax, 4 call kernel add esp, 12 push dword 0 mov eax, 1 call kernel ; number of characters ; stdout ; sys_write ; same as 3 x pop dword ; exit success value ; sys_exit $ uname -v Darwin Kernel Version : Tue Jun 7 16:33:36 PDT 2011; root:xnu ~1/release_i386 $ nasm -f macho hello.asm $ ld -o hello hello.o $./hello Hello, world! $ echo $? 0 $
17 Hello, world! kernel: int 80h %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 section.data greeting db 'Hello, world!', 0xa greeting_len equ $-greeting section.text global start start: push dword greeting_len push dword greeting push dword STDOUT mov eax, SYS_WRITE call kernel add esp, 12 push dword EXIT_SUCCESS mov eax, SYS_EXIT call kernel
18 Hello, world! mylib.inc kernel: int 0x80 %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 hello.asm %include "mylib.inc" section.data greeting db 'Hello, world!', 0xa greeting_len equ $-greeting section.text global start start: sys_write STDOUT, greeting, greeting_len sys_exit EXIT_SUCCESS %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT call kernel %endmacro %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel add esp, 12 %endmacro %macro sys_write 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_WRITE call kernel add esp, 12 %endmacro
19
20 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
21 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm
22 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm $ ld askme.o
23 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm $ ld askme.o $./a.out
24 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm $ ld askme.o $./a.out What is your name?
25 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm $ ld askme.o $./a.out What is your name? Larry
26 %include "mylib.inc" %define BUFFERSIZE 1024 global start start: section.data.str1 db "What is your name? ".len1 equ $-.str1.str2 db " is invincible!", 0xa.len2 equ $-.str2.buflen dd 0 section.bss.buf resb BUFFERSIZE section.text sys_write STDOUT,.str1,.len1 sys_read STDIN,.buf, BUFFERSIZE cmp eax, 0 jl.exit_with_failure je.exit_with_success mov [.buflen], eax sub [.buflen], dword 1 mov ecx, 10.again: sys_write STDOUT,.buf, [.buflen] sys_write STDOUT,.str2,.len2 dec ecx jnz.again.exit_with_success: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ nasm -f macho askme.asm $ ld askme.o $./a.out What is your name? Larry Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! $
27
28
29
30
31
32 Monday
33 Monday Hey, programmer. I got an idea. I need some stuff...
34 Monday Hey, programmer. I got an idea. I need some stuff... ok?
35 Monday Hey, programmer. I got an idea. I need some stuff... ok? a program that can calculate the scores in a dice game.
36 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. ok? which dice game?
37 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game?
38 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee?
39 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out?
40 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out? I guess so... but what kind of input do I get? And which format of output do you expect? And what is it going to be used for?
41 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out? Input, output, bits and bytes? GEEK! Why ask me? you are the programmer I guess so... but what kind of input do I get? And which format of output do you expect? And what is it going to be used for?
42 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out? Input, output, bits and bytes? GEEK! Why ask me? you are the programmer I guess so... but what kind of input do I get? And which format of output do you expect? And what is it going to be used for? eat flaming death!
43 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out? Input, output, bits and bytes? GEEK! Why ask me? you are the programmer I guess so... but what kind of input do I get? And which format of output do you expect? And what is it going to be used for? eat flaming death! I need it by friday. Right?
44 Monday Hey, programmer. I got an idea. I need some stuff... a program that can calculate the scores in a dice game. I need it by friday ok? which dice game? is it yahtzee? yeah, something like that, whatever, original american version? You only need to care about the lower section...you figure it out? Input, output, bits and bytes? GEEK! Why ask me? you are the programmer I guess so... but what kind of input do I get? And which format of output do you expect? And what is it going to be used for? eat flaming death! I need it by friday. Right? sure
45 vague initial requirement Write a library that can score the lower section of a game of yahtzee.
46 Examples (see also
47 yahtzee.asm yahtzee_tests.asm nasm yahtzee.o nasm yahtzee_tests.o ar yahtzee.a ld yahtzee_tests
48 Makefile all: yahtzee.a check: yahtzee_tests!./yahtzee_tests yahtzee.a: yahtzee.o! ar -rcs $^ yahtzee.o: yahtzee.asm mylib.inc! nasm -f macho $< yahtzee_tests.o: yahtzee_tests.asm mylib.inc! nasm -f macho $< yahtzee_tests: yahtzee_tests.o yahtzee.a! ld -o $^ clean:! rm -f a.out *.o *.a yahtzee_tests
49 yahtzee_tests.asm
50 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS
51 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check
52 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm
53 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm
54 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o
55 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a
56 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests
57 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests bash-3.2$ echo $?
58 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests bash-3.2$ echo $? 0
59 yahtzee_tests.asm %include "mylib.inc" global start start: sys_exit EXIT_SUCCESS make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests bash-3.2$ echo $? 0 bash-3.2$
60 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
61 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check
62 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm
63 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm
64 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o
65 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a
66 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests
67 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests make: *** [check] Error 1
68 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm nasm -f macho yahtzee.asm ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests make: *** [check] Error 1 $
69 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm Our first unit test failed. This is good! Exactly what we want. The nasm -f macho yahtzee.asm rythm of TDD is : fail, fix, pass... fail, fix, pass ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests make: *** [check] Error 1 $
70 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm Our first unit test failed. This is good! Exactly what we want. The Fail nasm - Fix - Pass -f macho yahtzee.asm rythm of TDD is : fail, fix, pass... fail, fix, pass ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests make: *** [check] Error 1 $
71 yahtzee_tests.asm %include "mylib.inc" global start start: mov eax, 6 imul eax, 9 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm Our first unit test failed. This is good! Exactly what we want. The Fail nasm - Fix - Pass -f macho yahtzee.asm rythm of TDD is : fail, fix, pass... fail, fix, pass ar -rcs yahtzee.a yahtzee.o ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests make: *** [check] Error 1 $
72 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
73 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check
74 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm
75 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a
76 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests
77 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests $
78 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests $
79 yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests $ All tests are OK!
80 Let s write a proper unit test yahtzee_tests.asm %include "mylib.inc" global start Fail - Fix - Pass start: mov eax, 6 imul eax, 7 cmp eax, 42 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass $ make check nasm -f macho yahtzee_tests.asm ld -o yahtzee_tests yahtzee_tests.o yahtzee.a./yahtzee_tests $ All tests are OK!
81
82
83
84 yahtzee_tests.asm %include "mylib.inc" section.text global start start: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
85 yahtzee_tests.asm %include "mylib.inc" section.text global start start: sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
86 yahtzee_tests.asm %include "mylib.inc" section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
87 yahtzee_tests.asm %include "mylib.inc" section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
88 yahtzee_tests.asm %include "mylib.inc" section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
89 yahtzee_tests.asm %include "mylib.inc" section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
90 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
91 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
92 yahtzee.asm yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
93 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword?? yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
94 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword?? what should we urn? yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
95 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword?? what should we urn? Remember fail-fix-pass? Return something that you know will fail. yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
96 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 0 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
97 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 0 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE make: *** [check] Error 1
98 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 0 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 Fail - Fix - Pass sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE make: *** [check] Error 1
99 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 0 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 Fail - Fix - Pass sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE make: *** [check] Error 1
100 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
101 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
102 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 Fail - Fix - Pass yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
103 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 Fail - Fix - Pass yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 Fail - Fix - Pass sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
104 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 Fail - Fix - Pass Congratulation. We have completed our first proper fail-fix-pass cycle. Returning 7 is a minimal change to make it pass. This is OK because what we are concerned about now is just to make sure that the wiring of the test is OK. Is the test really being called and is it testing the right function? yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 Fail - Fix - Pass sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
105 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 Fail - Fix - Pass Congratulation. We have completed our first proper fail-fix-pass cycle. Returning 7 is a minimal change to make it pass. This is OK because what we are concerned about now is just to make sure that the wiring of the test is OK. Is the test really being called and is it testing the right function? yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 Let s add another unit test. Fail - Fix - Pass section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
106 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 Fail - Fix - Pass Congratulation. We have completed our first proper fail-fix-pass cycle. Returning 7 is a minimal change to make it pass. This is OK because what we are concerned about now is just to make sure that the wiring of the test is OK. Is the test really being called and is it testing the right function? yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 Let s add another unit test. Fail - Fix - Pass section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE./yahtzee_tests
107 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
108 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
109 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
110 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
111 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
112 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
113 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
114 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE make: *** [check] Error 1
115 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass make: *** [check] Error 1
116 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind Should we cheat again and check for the last dice, if section 4 then urn.data 10 otherwise 7? dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass make: *** [check] Error 1
117 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: mov eax, dword 7 yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind Should we cheat again and check for the last dice, if section 4 then urn.data 10 otherwise 7? dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 No! Another principle of TDD is that while you are supposed to do simple and naive increments you are section.text not allowed to do obviously stupid stuff. global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass make: *** [check] Error 1
118 yahtzee.asm yahtzee_tests.asm global score_three_of_a_kind %include "mylib.inc" score_three_of_a_kind: mov eax, dword 7 extern score_three_of_a_kind Should we cheat again and check for the last dice, if section 4 then urn.data 10 otherwise 7? dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 No! Another principle of TDD is that while you are supposed to do simple and naive increments you are section.text not allowed to do obviously stupid stuff. global start start: A simple and naive thing to do here mov is to just esi, sum dice_11122 the and urn the value. That would satisfy call all score_three_of_a_kind the tests and we know the functionality will eventually cmp eax, be needed. dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass make: *** [check] Error 1
119 yahtzee.asm yahtzee_tests.asm global score_three_of_a_kind %include "mylib.inc" score_three_of_a_kind: mov eax, dword 7 extern score_three_of_a_kind Should we cheat again and check for the last dice, if section 4 then urn.data 10 otherwise 7? dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 No! Another principle of TDD is that while you are supposed to do simple and naive increments you are section.text not allowed to do obviously stupid stuff. global start start: A simple and naive thing to do here mov is to just esi, sum dice_11122 the and urn the value. That would satisfy call all score_three_of_a_kind the tests and we know the functionality will eventually cmp eax, be needed. dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass make: *** [check] Error 1
120 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
121 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
122 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
123 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
124 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 Fail - Fix - Pass dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
125 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 Fail - Fix - Pass dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE Fail - Fix - Pass./yahtzee_tests
126 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
127 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
128 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
129 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
130 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
131 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE make: *** [check] Error 1
132 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
133 yahtzee.asm global score_three_of_a_kind score_three_of_a_kind: call sum_of_dice sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
134 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice... yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
135 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice... yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
136 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice... yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
137 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
138 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE yahtzee_tests.asm... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
139 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov yahtzee_tests.asm eax, 0 cmp... ebx, [esi+0] jne.next1 inc section eax.data.next1: dice_11122 dd 1,1,1,2,2 cmp dice_11134 ebx, [esi+4] dd 1,1,1,3,4 jne dice_12345.next2 dd 1,2,3,4,5 inc eax.next2: section.text cmp global ebx, start [esi+8] jne start:.next3 inc eax mov esi, dice_11122.next3: cmp ebx, [esi+12] cmp eax, dword 7 jne.next4 inc eax.next4: mov esi, dice_11134 cmp ebx, [esi+16] jne.next5cmp eax, dword 10 inc eax.next5: mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
140 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE./yahtzee_tests count_face: mov yahtzee_tests.asm eax, 0 cmp... ebx, [esi+0] jne.next1 inc section eax.data.next1: dice_11122 dd 1,1,1,2,2 cmp dice_11134 ebx, [esi+4] dd 1,1,1,3,4 jne dice_12345.next2 dd 1,2,3,4,5 inc eax.next2: section.text cmp global ebx, start [esi+8] jne start:.next3 inc eax mov esi, dice_11122.next3: cmp ebx, [esi+12] cmp eax, dword 7 jne.next4 inc eax.next4: mov esi, dice_11134 cmp ebx, [esi+16] jne.next5cmp eax, dword 10 inc eax.next5: mov esi, dice_12345 cmp eax, dword 0 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
141 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0./yahtzee_tests...
142 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0./yahtzee_tests...
143 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20...
144 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20./yahtzee_tests...
145 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20./yahtzee_tests...
146 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20./yahtzee_tests...
147 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20...
148 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20./yahtzee_tests...
149 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20./yahtzee_tests...
150 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 Looking good! Looking good! cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20./yahtzee_tests...
151 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 Looking good! Looking good! cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20./yahtzee_tests...
152 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword mov esi, dice_61666 cmp eax, dword 18+7
153 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20 make: *** [check] Error 1... mov esi, dice_61666 cmp eax, dword 18+7
154 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20 make: *** [check] Error 1... mov esi, dice_61666 cmp eax, dword 18+7
155 yahtzee_tests.asm... mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20 Oh no... what happened? make: *** [check] Error 1... mov esi, dice_61666 cmp eax, dword 18+7
156 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5:
157 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5:
158 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: But of course...
159 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: But of course...
160 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: But of course... it should be at least three...
161 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 je.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE
162 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE
163 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE
164 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE
165 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE
166 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE./yahtzee_tests
167 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE./yahtzee_tests
168 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE./yahtzee_tests
169 yahtzee.asm %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice phew! have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE./yahtzee_tests
170
171
172 code developed so far %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 dice_53552 dd 5,3,5,5,2 dice_11666 dd 1,1,6,6,6 dice_61666 dd 6,1,6,6,6 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20 mov esi, dice_61666 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
173 code developed so far %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16] %include "mylib.inc" extern score_three_of_a_kind section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 dice_53552 dd 5,3,5,5,2 dice_11666 dd 1,1,6,6,6 dice_61666 dd 6,1,6,6,6 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0 mov esi, dice_53552 cmp eax, dword 20 mov esi, dice_11666 cmp eax, dword 20 mov esi, dice_61666 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
174 ... section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 dice_53552 dd 5,3,5,5,2 dice_11666 dd 1,1,6,6,6 dice_61666 dd 6,1,6,6,6 section.text global start start: mov esi, dice_11122 cmp eax, dword 7... mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0
175 ... Is it possible to make this look better? section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 dice_53552 dd 5,3,5,5,2 dice_11666 dd 1,1,6,6,6 dice_61666 dd 6,1,6,6,6 section.text global start start: mov esi, dice_11122 cmp eax, dword 7... mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0
176 ... Is it possible to make this look better? I have an idea. Lets rewrite it a bit section.data dice_11122 dd 1,1,1,2,2 dice_11134 dd 1,1,1,3,4 dice_12345 dd 1,2,3,4,5 dice_53552 dd 5,3,5,5,2 dice_11666 dd 1,1,6,6,6 dice_61666 dd 6,1,6,6,6 section.text global start start: mov esi, dice_11122 cmp eax, dword 7 mov esi, dice_11134 cmp eax, dword 10 mov esi, dice_12345 cmp eax, dword 0...
177 ... section.text global start start: section.data dice_11122 dd 1,1,1,2,2 section.text mov esi, dice_11122 cmp eax, dword 7 section.data dice_11134 dd 1,1,1,3,4 section.text mov esi, dice_11134 cmp eax, dword 10 section.data dice_12345 dd 1,2,3,4,5 section.text mov esi, dice_12345 cmp eax, dword 0
178 ... section.text global start start: section.data dice_11122 dd 1,1,1,2,2 section.text mov esi, dice_11122 cmp eax, dword 7 now we recognize a recurring pattern section.data dice_11134 dd 1,1,1,3,4 section.text mov esi, dice_11134 cmp eax, dword 10 section.data dice_12345 dd 1,2,3,4,5 section.text mov esi, dice_12345 cmp eax, dword 0
179 ... section.text global start start: section.data dice_11122 dd 1,1,1,2,2 section.text mov esi, dice_11122 cmp eax, dword 7 now we recognize a recurring pattern section.data dice_11134 dd 1,1,1,3,4 section.text mov esi, dice_11134 cmp eax, dword 10 section.data dice_12345 dd 1,2,3,4,5 section.text mov esi, dice_12345 cmp eax, dword 0
180 ... section.text global start start: section.data dice_11122 dd 1,1,1,2,2 section.text mov esi, dice_11122 cmp eax, dword 7 now we recognize a recurring pattern and it is easy to introduce a macro section.data dice_11134 dd 1,1,1,3,4 section.text mov esi, dice_11134 cmp eax, dword 10 section.data dice_12345 dd 1,2,3,4,5 section.text mov esi, dice_12345 cmp eax, dword 0
181 ... %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro now we recognize a recurring pattern and it is easy to introduce a macro section.text global start start: section.data dice_11122 dd 1,1,1,2,2 section.text mov esi, dice_11122 cmp eax, dword 7 section.data dice_11134 dd 1,1,1,3,4 section.text mov esi, dice_11134 cmp eax, dword 10 section.data dice_12345 dd 1,2,3,4,5 section.text mov esi, dice_12345 cmp eax, dword 0
182 %include "mylib.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 cmp eax, dword 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 cmp eax, dword 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 cmp eax, dword 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 cmp eax, dword 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 cmp eax, dword 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
183 %include "mylib.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 cmp eax, dword 7 Slightly better. Perhaps we can introduce another macro as well? eval_dice score_three_of_a_kind, 1,1,1,3,4 cmp eax, dword 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 cmp eax, dword 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 cmp eax, dword 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 cmp eax, dword 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
184 %include "mylib.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 cmp eax, dword 7 Slightly better. Perhaps we can introduce another macro as well? eval_dice score_three_of_a_kind, 1,1,1,3,4 cmp eax, dword 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 cmp eax, dword 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 cmp eax, dword 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 cmp eax, dword 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
185 %include "mylib.inc" %macro TEST_assert_eax_equals 1 sub eax, dword %1 jz %%ok sys_exit EXIT_FAILURE %%ok: nop %endmacro Slightly better. Perhaps we can introduce another macro as well? %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 cmp eax, dword 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 cmp eax, dword 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 cmp eax, dword 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 cmp eax, dword 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 cmp eax, dword 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 cmp eax, dword 18+7 sys_exit EXIT_SUCCESS.exit_with_failure: sys_exit EXIT_FAILURE
186 %include "mylib.inc" %macro TEST_assert_eax_equals 1 sub eax, dword %1 jz %%ok sys_exit EXIT_FAILURE %%ok: nop %endmacro %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 TEST_assert_eax_equals 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 TEST_assert_eax_equals 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 TEST_assert_eax_equals 18+7
187 %include "mylib.inc" %macro TEST_assert_eax_equals 1 sub eax, dword %1 jz %%ok sys_exit EXIT_FAILURE %%ok: nop %endmacro %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro this is starting to look good. Perhaps we could reorganize the code, and print out a nice message if everything is OK extern score_three_of_a_kind section.text global start start: eval_dice score_three_of_a_kind, 1,1,1,2,2 TEST_assert_eax_equals 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 TEST_assert_eax_equals 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 TEST_assert_eax_equals 18+7
188 %include "mylib.inc" %macro TEST_assert_eax_equals 1 sub eax, dword %1 jz %%ok sys_exit EXIT_FAILURE %%ok: nop %endmacro %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro extern score_three_of_a_kind check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,2,2 TEST_assert_eax_equals 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 TEST_assert_eax_equals 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 TEST_assert_eax_equals 18+7 section.text global start start: section.data.msg db 'Larry is invincible!', 0xa.len equ $-.msg section.text call check_score_three_of_a_kind sys_write STDOUT,.msg,.len sys_exit EXIT_SUCCESS
189 %include "mylib.inc" extern score_three_of_a_kind $ make check %macro TEST_assert_eax_equals nasm -f macho yahtzee_tests.asm 1 sub nasm eax, -f dword macho %1yahtzee.asm jz %%ok ar -rcs yahtzee.a yahtzee.o sys_exit ld -o yahtzee_tests EXIT_FAILURE yahtzee_tests.o yahtzee.a %%ok: nop %endmacro./yahtzee_tests Larry is invincible! $ make check./yahtzee_tests Larry is invincible! %macro eval_dice $ make 6check./yahtzee_tests section.data Larry is invincible! %%dice $ make dd check %2,%3,%4,%5,%6 section.text./yahtzee_tests mov Larry esi, is %%dice invincible! call $ %1 make check %endmacro./yahtzee_tests Larry is invincible! $ check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,2,2 TEST_assert_eax_equals 7 eval_dice score_three_of_a_kind, 1,1,1,3,4 TEST_assert_eax_equals 10 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 5,3,5,5,2 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 1,1,6,6,6 TEST_assert_eax_equals 20 eval_dice score_three_of_a_kind, 6,1,6,6,6 TEST_assert_eax_equals 18+7 section.text global start start: section.data.msg db 'Larry is invincible!', 0xa.len equ $-.msg section.text call check_score_three_of_a_kind sys_write STDOUT,.msg,.len sys_exit EXIT_SUCCESS
190 %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: so what about the implementation? Can we do much more here? sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16]
191 %define TRUE 1 %define FALSE 0 global score_three_of_a_kind score_three_of_a_kind: call have_at_least_3_of_a_kind cmp eax, TRUE je.urn_sum.urn_zero: mov eax, 0.urn_sum: call sum_of_dice have_at_least_3_of_a_kind: mov ebx, 1 ; face value.check_next_face_value: call count_face cmp eax, 3 jge.urn_true inc ebx cmp ebx, 6 jg.urn_false jmp.check_next_face_value.urn_false: mov eax, FALSE.urn_true: mov eax, TRUE count_face: mov eax, 0 cmp ebx, [esi+0] jne.next1 inc eax.next1: cmp ebx, [esi+4] jne.next2 inc eax.next2: cmp ebx, [esi+8] jne.next3 inc eax.next3: cmp ebx, [esi+12] jne.next4 inc eax.next4: cmp ebx, [esi+16] jne.next5 inc eax.next5: so what about the implementation? Can we do much more here? am I allowed to comment the code? sum_of_dice: mov eax, [esi+0] add eax, [esi+4] add eax, [esi+8] add eax, [esi+12] add eax, [esi+16]
192
193
194
195
196
197
198
199 Larrys ad-hoc unit test framework for assembler (aka, OSL) ; ; Larrys adhoc unit test framework (aka, OSL) ; section.data TEST_tests dd 0 TEST_errflag dd 0 TEST_errors dd 0 TEST_okchar db '.' TEST_errchar db 'X' TEST_okstr db ' OK', 0xa TEST_okstr_len equ $-TEST_okstr TEST_errstr db ' FAILED', 0xa TEST_errstr_len equ $-TEST_errstr section.text %macro TEST_runtests 1 section.data %defstr %1_str %1 %%prefix db %1_str, ' ' %%prefix_len equ $-%%prefix section.text sys_write STDOUT, %%prefix, %%prefix_len mov [TEST_errflag], dword 0 call %1 cmp [TEST_errflag], dword 0 jne %%print_err sys_write STDOUT, TEST_okstr, TEST_okstr_len jmp %%cont %%print_err: sys_write STDOUT, TEST_errstr, TEST_errstr_len %%cont: %endmacro %macro TEST_assert_eax_equals 1 sub eax, dword %1 jz %%ok add [TEST_tests], dword 1 add [TEST_errors], dword 1 add [TEST_errflag], dword 1 sys_write STDOUT, TEST_errchar, 1 jmp %%exit %%ok: add [TEST_tests], dword 1 sys_write STDOUT, TEST_okchar, 1 %%exit: nop %endmacro %macro TEST_exit 0 cmp [TEST_errors], dword 0 jne.exit_success.exit_success: sys_exit EXIT_SUCCESS.exit_failure: sys_exit EXIT_FAILURE %endmacro
200 Larrys ad-hoc unit test framework for assembler (aka, OSL) %macro TEST_print_eax 0 section.data %%ch db '.' section.text push eax push ebx push ecx push edx mov ebx, 0 %%divide_and_push_remainder: mov edx, 0 mov ecx, 10 div ecx ; eax = quotient, edx = remainder add edx, '0' push edx inc ebx cmp eax, 0 jne %%divide_and_push_remainder %%pop_and_print: pop eax mov [%%ch], al sys_write STDOUT, %%ch, 1 dec ebx jg %%pop_and_print %%exit: pop edx pop ecx pop ebx pop eax %endmacro %macro TEST_print_summary 0 section.data %%str0 db 'CHECK ', FILE, " -> " %%str0_len equ $-%%str0 %%str1 db " tests executed. " %%str1_len equ $-%%str1 %%str2 db " failed.)", 0xa %%str2_len equ $-%%str2 %%str3 db "OK (" %%str3_len equ $-%%str3 %%str4 db "FAILED (" %%str4_len equ $-%%str4 section.text sys_write STDOUT, %%str0, %%str0_len cmp [TEST_errors], dword 0 jne.print_failure sys_write STDOUT, %%str3, %%str3_len jmp.cont.print_failure: sys_write STDOUT, %%str4, %%str4_len.cont: push eax mov eax, [TEST_tests] TEST_print_eax sys_write STDOUT, %%str1, %%str1_len mov eax, [TEST_errors] TEST_print_eax sys_write STDOUT, %%str2, %%str2_len pop eax %endmacro
201 the unit tests for the yahtzee library %include "mylib.inc" %include "mytest.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro ; ; functions to test ; extern score_chance extern score_yahtzee extern score_three_of_a_kind extern score_four_of_a_kind extern score_small_straight extern score_large_straight extern score_full_house ; ; test functions ; check_score_chance: eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_chance, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_chance, 1,2,3,4,5 TEST_assert_eax_equals 15 eval_dice score_chance, 6,5,4,3,2 TEST_assert_eax_equals 20 check_score_yahtzee: eval_dice score_yahtzee, 1,1,1,1,1 TEST_assert_eax_equals 50 eval_dice score_yahtzee, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 1,1,1,1,2 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 6,6,6,6,6 TEST_assert_eax_equals 50 check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_three_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_three_of_a_kind, 6,5,4,3,2 TEST_assert_eax_equals 0 check_score_four_of_a_kind: eval_dice score_four_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_four_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_four_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_four_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 check_score_small_straight: eval_dice score_small_straight, 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 6,5,4,3,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 check_score_large_straight: eval_dice score_large_straight, 1,2,3,4,5 TEST_assert_eax_equals 40 eval_dice score_large_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_large_straight, 6,5,4,3,2 TEST_assert_eax_equals 40 check_score_full_house: eval_dice score_full_house, 3,3,3,5,5 TEST_assert_eax_equals 25 eval_dice score_full_house, 3,5,3,5,5 TEST_assert_eax_equals 25 eval_dice score_full_house, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_full_house, 2,3,2,3,1 TEST_assert_eax_equals 0 global start start: TEST_runtests check_score_chance TEST_runtests check_score_yahtzee TEST_runtests check_score_three_of_a_kind TEST_runtests check_score_four_of_a_kind TEST_runtests check_score_small_straight TEST_runtests check_score_large_straight TEST_runtests check_score_full_house TEST_print_summary TEST_exit
202 the unit tests for the yahtzee library %include "mylib.inc" %include "mytest.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro ; ; functions to test ; extern score_chance extern score_yahtzee extern score_three_of_a_kind extern score_four_of_a_kind extern score_small_straight extern score_large_straight extern score_full_house ; ; test functions ; check_score_chance: eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_chance, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_chance, 1,2,3,4,5 TEST_assert_eax_equals 15 eval_dice score_chance, 6,5,4,3,2 TEST_assert_eax_equals 20 check_score_yahtzee: eval_dice score_yahtzee, 1,1,1,1,1 TEST_assert_eax_equals 50 eval_dice score_yahtzee, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 1,1,1,1,2 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 6,6,6,6,6 TEST_assert_eax_equals 50 check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_three_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_three_of_a_kind, 6,5,4,3,2 TEST_assert_eax_equals 0 %include "mylib.inc" %include "mytest.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro ; ; functions to test ; extern score_chance extern score_yahtzee extern score_three_of_a_kind extern score_four_of_a_kind extern score_small_straight extern score_large_straight extern score_full_house check_score_four_of_a_kind: eval_dice score_four_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_four_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_four_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_four_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 check_score_small_straight: eval_dice score_small_straight, 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 6,5,4,3,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 check_score_large_straight: eval_dice score_large_straight, 1,2,3,4,5 TEST_assert_eax_equals 40 eval_dice score_large_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_large_straight, 6,5,4,3,2 TEST_assert_eax_equals 40 check_score_full_house: eval_dice score_full_house, 3,3,3,5,5 TEST_assert_eax_equals 25 eval_dice score_full_house, 3,5,3,5,5 TEST_assert_eax_equals 25 eval_dice score_full_house, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_full_house, 2,3,2,3,1 TEST_assert_eax_equals 0 global start start: TEST_runtests check_score_chance TEST_runtests check_score_yahtzee TEST_runtests check_score_three_of_a_kind TEST_runtests check_score_four_of_a_kind TEST_runtests check_score_small_straight TEST_runtests check_score_large_straight TEST_runtests check_score_full_house TEST_print_summary TEST_exit
203 the unit tests for the yahtzee library %include "mylib.inc" %include "mytest.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro %include "mylib.inc" %include "mytest.inc" check_score_four_of_a_kind: eval_dice score_four_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_four_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_four_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 ; ; functions to test ; extern score_chance extern score_yahtzee extern score_three_of_a_kind extern score_four_of_a_kind extern score_small_straight extern score_large_straight extern score_full_house ; ; test functions ; check_score_chance: eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_chance, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_chance, 1,2,3,4,5 TEST_assert_eax_equals 15 eval_dice score_chance, 6,5,4,3,2 TEST_assert_eax_equals 20 check_score_yahtzee: eval_dice score_yahtzee, 1,1,1,1,1 TEST_assert_eax_equals 50 eval_dice score_yahtzee, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 1,1,1,1,2 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 6,6,6,6,6 TEST_assert_eax_equals 50 check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_three_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_three_of_a_kind, 6,5,4,3,2 TEST_assert_eax_equals 0 %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text check_score_small_straight: mov esi, check_score_small_straight: check_score_small_straight: %%dice eval_dice score_small_straight, 1,2,3,4,5 call %1 TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,5 %endmacro TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 ; TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,1 ; functions to test TEST_assert_eax_equals 30 TEST_assert_eax_equals 30 ; eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals eval_dice score_small_straight, 0 1,2,4,5,6 extern score_chance TEST_assert_eax_equals eval_dice score_small_straight, 0 1,2,4,5,6 TEST_assert_eax_equals 0 extern score_yahtzeeval_dice score_small_straight, 6,5,4,3,1 extern score_three_of_a_kind TEST_assert_eax_equals 30 check_score_full_house: extern score_four_of_a_kind TEST_assert_eax_equals eval_dice score_small_straight, 30 6,5,4,3,1 eval_dice score_full_house, 3,3,3,5,5 TEST_assert_eax_equals 30TEST_assert_eax_equals 25 extern score_small_straight eval_dice score_small_straight, eval_dice 6,6,6,6,6 score_full_house, 3,5,3,5,5 TEST_assert_eax_equals 25 extern score_large_straight TEST_assert_eax_equals eval_dice score_small_straight, 0 6,6,6,6,6 eval_dice score_full_house, extern score_full_house TEST_assert_eax_equals eval_dice score_small_straight, 0 6,6,6,6,6 TEST_assert_eax_equals 0 TEST_assert_eax_equals 0 eval_dice score_full_house, 2,3,2,3,1 TEST_assert_eax_equals 0 eval_dice score_four_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 check_score_small_straight: eval_dice score_small_straight, 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 6,5,4,3,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 1,2,3,4,1 check_score_large_straight: eval_dice score_large_straight, 1,2,3,4,5 TEST_assert_eax_equals 40 eval_dice score_large_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_large_straight, 6,5,4,3,2 TEST_assert_eax_equals 40 eval_dice score_small_straight, 6,5,4,3,1 global start start: TEST_runtests check_score_chance TEST_runtests check_score_yahtzee TEST_runtests check_score_three_of_a_kind TEST_runtests check_score_four_of_a_kind TEST_runtests check_score_small_straight TEST_runtests check_score_large_straight TEST_runtests check_score_full_house TEST_print_summary TEST_exit
204 the unit tests for the yahtzee library %include "mylib.inc" %include "mytest.inc" %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text mov esi, %%dice call %1 %endmacro %include "mylib.inc" %include "mytest.inc" check_score_four_of_a_kind: eval_dice score_four_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_four_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_four_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 ; ; functions to test ; extern score_chance extern score_yahtzee extern score_three_of_a_kind extern score_four_of_a_kind extern score_small_straight extern score_large_straight extern score_full_house ; ; test functions ; check_score_chance: eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_chance, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_chance, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_chance, 1,2,3,4,5 TEST_assert_eax_equals 15 eval_dice score_chance, 6,5,4,3,2 TEST_assert_eax_equals 20 check_score_yahtzee: eval_dice score_yahtzee, 1,1,1,1,1 TEST_assert_eax_equals 50 eval_dice score_yahtzee, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 1,1,1,1,2 TEST_assert_eax_equals 0 eval_dice score_yahtzee, 6,6,6,6,6 TEST_assert_eax_equals 50 check_score_three_of_a_kind: eval_dice score_three_of_a_kind, 1,1,1,1,1 TEST_assert_eax_equals 5 eval_dice score_three_of_a_kind, 1,1,1,1,2 TEST_assert_eax_equals 6 eval_dice score_three_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 eval_dice score_three_of_a_kind, 6,6,6,6,6 TEST_assert_eax_equals 30 eval_dice score_three_of_a_kind, 6,5,4,3,2 TEST_assert_eax_equals 0 %macro eval_dice 6 section.data %%dice dd %2,%3,%4,%5,%6 section.text check_score_small_straight: mov esi, check_score_small_straight: check_score_small_straight: %%dice eval_dice score_small_straight, 1,2,3,4,5 call %1 TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,5 %endmacro TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 ; TEST_assert_eax_equals eval_dice score_small_straight, 30 1,2,3,4,1 ; functions to test TEST_assert_eax_equals 30 TEST_assert_eax_equals 30 ; eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals eval_dice score_small_straight, 0 1,2,4,5,6 extern score_chance TEST_assert_eax_equals eval_dice score_small_straight, 0 1,2,4,5,6 TEST_assert_eax_equals 0 extern score_yahtzeeval_dice score_small_straight, 6,5,4,3,1 extern score_three_of_a_kind TEST_assert_eax_equals 30 check_score_full_house: extern score_four_of_a_kind TEST_assert_eax_equals eval_dice score_small_straight, 30 6,5,4,3,1 eval_dice score_full_house, 3,3,3,5,5 TEST_assert_eax_equals 30TEST_assert_eax_equals 25 extern score_small_straight eval_dice score_small_straight, eval_dice 6,6,6,6,6 score_full_house, 3,5,3,5,5 TEST_assert_eax_equals 25 extern score_large_straight TEST_assert_eax_equals eval_dice score_small_straight, 0 6,6,6,6,6 eval_dice score_full_house, extern score_full_house TEST_assert_eax_equals eval_dice score_small_straight, 0 6,6,6,6,6 TEST_assert_eax_equals 0 TEST_assert_eax_equals 0 eval_dice score_full_house, 2,3,2,3,1 TEST_assert_eax_equals 0 eval_dice score_four_of_a_kind, 1,2,3,4,5 TEST_assert_eax_equals 0 check_score_small_straight: eval_dice score_small_straight, 1,2,3,4,5 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,3,4,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 1,2,4,5,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 6,5,4,3,1 TEST_assert_eax_equals 30 eval_dice score_small_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_small_straight, 1,2,3,4,1 check_score_large_straight: eval_dice score_large_straight, 1,2,3,4,5 TEST_assert_eax_equals 40 eval_dice score_large_straight, 6,6,6,6,6 TEST_assert_eax_equals 0 eval_dice score_large_straight, 6,5,4,3,2 TEST_assert_eax_equals 40 eval_dice score_small_straight, 6,5,4,3,1 global start start: TEST_runtests check_score_chance TEST_runtests check_score_yahtzee TEST_runtests check_score_three_of_a_kind TEST_runtests check_score_four_of_a_kind TEST_runtests check_score_small_straight TEST_runtests check_score_large_straight TEST_runtests check_score_full_house global start start: TEST_runtests check_score_chance TEST_runtests check_score_yahtzee TEST_runtests check_score_three_of_a_kind TEST_runtests check_score_four_of_a_kind TEST_runtests check_score_small_straight TEST_runtests check_score_large_straight TEST_runtests check_score_full_house TEST_print_summary TEST_exit TEST_print_summary TEST_exit
205
206
207
208 Wednesday
209 are you done? Wednesday
210 Wednesday are you done? I have something
211 Wednesday are you done? I have something can you show me
212 Wednesday are you done? can you show me I have something eh...
213 $ for ((i=0; i<10; i++)); do make check; done Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! Larry is invincible! $
214 eh... you are finished by friday?
215 eh... you are finished by friday? but...
216 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file
217 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file What is the input format? What should the output format be? Any performance requirements?
218 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file Input, output, bits and bytes? GEEK! Why ask me? you are the programmer What is the input format? What should the output format be? Any performance requirements?
219 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file Input, output, bits and bytes? GEEK! Why ask me? you are the programmer What is the input format? What should the output format be? Any performance requirements? eat flaming death!
220 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file Input, output, bits and bytes? GEEK! Why ask me? you are the programmer What is the input format? What should the output format be? Any performance requirements? eat flaming death! I need it by friday. Right?
221 eh... you are finished by friday? but... your program must be able to read a file with lots of dice, and then write all possible scores into a new file Input, output, bits and bytes? GEEK! Why ask me? you are the programmer I need it by friday. Right? What is the input format? What should the output format be? Any performance requirements? eat flaming death! sure
222 ... Larry implements the yahtzee_demo... (using FDD)
223
224
225 Thursday
226 can you show me something Thursday
227 Thursday can you show me something yes, here is a demo
228
229 ./yahtzee_demo
230 ./yahtzee_demo 34456
231 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=22
232 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=
233 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C=5
234 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C=
235 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C=6
236 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C=
237 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C=30
238 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C=
239 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C=15
240 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C=
241 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C=20
242 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C=
243 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=11
244 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=
245 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C=18
246 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C=
247 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=19
248 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C=
249 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C=19
250 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C=
251 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C= dice=35355: 3=21, 4=0, H=25, S=0, L=0, Y=0, C=21
252 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C= dice=35355: 3=21, 4=0, H=25, S=0, L=0, Y=0, C=
253 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C= dice=35355: 3=21, 4=0, H=25, S=0, L=0, Y=0, C= dice=23231: 3=0, 4=0, H=0, S=0, L=0, Y=0, C=11
254 ./yahtzee_demo dice=34456: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=11111: 3=5, 4=5, H=0, S=0, L=0, Y=50, C= dice=11112: 3=6, 4=6, H=0, S=0, L=0, Y=0, C= dice=66666: 3=30, 4=30, H=0, S=0, L=0, Y=50, C= dice=12345: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=65432: 3=0, 4=0, H=0, S=30, L=40, Y=0, C= dice=12341: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=12456: 3=0, 4=0, H=0, S=0, L=0, Y=0, C= dice=65431: 3=0, 4=0, H=0, S=30, L=0, Y=0, C= dice=33355: 3=19, 4=0, H=25, S=0, L=0, Y=0, C= dice=35355: 3=21, 4=0, H=25, S=0, L=0, Y=0, C= dice=23231: 3=0, 4=0, H=0, S=0, L=0, Y=0, C=11 $
255
256 Thursday
257 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast.
258 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast ? Fast? How fast?
259 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast ? Fast? How fast? can you do it in a few seconds?
260 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast ? Fast? How fast? can you do it in a few seconds? eat flaming death!
261 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast ? Fast? How fast? can you do it in a few seconds? eat flaming death! I need it by tomorrow. Right?
262 Thursday Looks good! Seems like you are done already... The files you receive will have about a dice, and you need to calculate the score pty fast ? Fast? How fast? can you do it in a few seconds? eat flaming death! I need it by tomorrow. Right? sure
263 last minute requirement: must have buffered IO
264 last minute requirement: must have buffered IO - write a char to output buffer
265 last minute requirement: must have buffered IO - write a char to output buffer - flush output buffer
266 last minute requirement: must have buffered IO - write a char to output buffer - flush output buffer - read a char from an input buffer
267 last minute requirement: must have buffered IO - write a char to output buffer - flush output buffer - read a char from an input buffer - fill input buffer
268 kernel: int 0x80 %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT call kernel %endmacro %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel add esp, 12 %endmacro %macro sys_write 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_WRITE call kernel add esp, 12 %endmacro How to use TDD to implement buffered IO? my_write_char: push eax mov esi, esp sys_write STDOUT, esi, 1 add esp, 4 my_read_char: push dword 0 mov edi, esp sys_read STDIN, edi, 1 pop eax global start start: call my_read_char cmp eax, 0 jz.exit_success jl.exit_failure call my_write_char jmp start.exit_success: sys_exit EXIT_SUCCESS.exit_failure: sys_exit EXIT_FAILURE
269 kernel: int 0x80 %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT call kernel %endmacro %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel add esp, 12 %endmacro %macro sys_write 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_WRITE call kernel add esp, 12 %endmacro
270 kernel: int 0x80 %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT call kernel %endmacro %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel add esp, 12 %endmacro %macro sys_write 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_WRITE call kernel add esp, 12 %endmacro
271 kernel: %ifdef USE_TEST_KERNEL int 0x80 jmp test_kernel %endif int 0x80 kernel: %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT call kernel %endmacro %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel add esp, 12 %endmacro %macro sys_write 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_WRITE call kernel add esp, 12 %endmacro
272 kernel: %ifdef USE_TEST_KERNEL int 0x80 jmp test_kernel %endif int 0x80 kernel: %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %define USE_TEST_KERNEL %include "mylib.asm" %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT... call kernel %endmacro section.data test_kernel_eax dd 0 test_kernel_stack_0 dd 0 test_kernel_stack_1 dd 0 test_kernel_stack_2 dd 0 test_kernel_one_time_jmp dd 0 %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel section add.text esp, 12 %endmacro test_kernel: cmp [test_kernel_one_time_jmp], dword 0 je.call_normal_kernel jmp [test_kernel_one_time_jmp] %macro sys_write 3 push dword %3 push dword %2 push dword %1.call_normal_kernel: mov eax, SYS_WRITE call int kernel 80h add esp, 12 %endmacro
273 kernel: %ifdef USE_TEST_KERNEL int 0x80 jmp test_kernel %endif int 0x80 kernel: %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %define USE_TEST_KERNEL %include "mylib.asm" %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT... call kernel %endmacro section.data test_kernel_eax dd 0 test_kernel_stack_0 dd 0 test_kernel_stack_1 dd 0 test_kernel_stack_2 dd 0 test_kernel_one_time_jmp dd 0 %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel section add.text esp, 12 %endmacro test_kernel: cmp [test_kernel_one_time_jmp], dword 0 je.call_normal_kernel jmp [test_kernel_one_time_jmp] %macro sys_write 3 push dword %3 push dword %2 push dword %1.call_normal_kernel: mov eax, SYS_WRITE call int kernel 80h add esp, 12 %endmacro check_flushing: mov [test_kernel_one_time_jmp], dword.my_fake_kernel call myio_flush mov eax, [test_kernel_eax] TEST_assert_eax_equals SYS_WRITE mov eax, [test_kernel_stack_0] TEST_assert_eax_equals dword STDOUT mov eax, [test_kernel_stack_1] TEST_assert_eax_equals myio_obuffer mov eax, [test_kernel_stack_2] TEST_assert_eax_equals 0.my_fake_kernel: mov [test_kernel_one_time_jmp], dword 0 mov [test_kernel_eax], eax mov eax, [esp+4] mov [test_kernel_stack_0], eax mov eax, [esp+8] mov [test_kernel_stack_1], eax mov eax, [esp+12] mov [test_kernel_stack_2], eax mov eax, [test_kernel_stack_2]
274 kernel: %ifdef USE_TEST_KERNEL int 0x80 jmp test_kernel %endif int 0x80 kernel: %define SYS_EXIT 1 %define SYS_READ 3 %define SYS_WRITE 4 %define STDIN 0 %define STDOUT 1 %define STDERR 2 %define EXIT_SUCCESS 0 %define EXIT_FAILURE 1 %define USE_TEST_KERNEL %include "mylib.asm" %macro sys_exit 1 push dword %1 mov eax, SYS_EXIT... call kernel %endmacro section.data test_kernel_eax dd 0 test_kernel_stack_0 dd 0 test_kernel_stack_1 dd 0 test_kernel_stack_2 dd 0 test_kernel_one_time_jmp dd 0 %macro sys_read 3 push dword %3 push dword %2 push dword %1 mov eax, SYS_READ call kernel section add.text esp, 12 %endmacro test_kernel: cmp [test_kernel_one_time_jmp], dword 0 je.call_normal_kernel jmp [test_kernel_one_time_jmp] %macro sys_write 3 push dword %3 push dword %2 push dword %1.call_normal_kernel: mov eax, SYS_WRITE call int kernel 80h add esp, 12 %endmacro check_flushing: mov [test_kernel_one_time_jmp], dword.my_fake_kernel call myio_flush mov eax, [test_kernel_eax] TEST_assert_eax_equals SYS_WRITE mov eax, [test_kernel_stack_0] TEST_assert_eax_equals dword STDOUT mov eax, [test_kernel_stack_1] TEST_assert_eax_equals myio_obuffer mov eax, [test_kernel_stack_2] TEST_assert_eax_equals 0.my_fake_kernel: mov [test_kernel_one_time_jmp], dword 0 mov [test_kernel_eax], eax mov eax, [esp+4] mov [test_kernel_stack_0], eax mov eax, [esp+8] mov [test_kernel_stack_1], eax mov eax, [esp+12] mov [test_kernel_stack_2], eax mov eax, [test_kernel_stack_2] global start start: TEST_runtests check_empty_buffers TEST_runtests check_flushing TEST_runtests check_write_char TEST_runtests check_read_char TEST_runtests check_filling TEST_print_summary TEST_exit
275 %include "mylib.inc" section.data myio_obuffer_len dd 0 myio_ibuffer_len dd 0 myio_ibuffer_idx dd 0 %define BUFFERSIZE 1024 section.bss myio_obuffer resb BUFFERSIZE myio_ibuffer resb BUFFERSIZE section.text ; myio_flush ; actually write whatever is in the output buffer to STDOUT global myio_flush myio_flush: pusha mov esi, myio_obuffer mov ecx, [myio_obuffer_len].try_again: sys_write STDOUT, esi, ecx cmp eax, 0 jl.exit_with_failure add esi, eax sub ecx, eax jnz.try_again mov [myio_obuffer_len], dword 0 popa.exit_with_failure: sys_exit EXIT_FAILURE ; myio_write_char ; put one character in the output buffer, flush if necessary global myio_write_char myio_write_char: pusha mov edi, myio_obuffer add edi, [myio_obuffer_len] mov [edi], al add [myio_obuffer_len], dword 1 cmp [myio_obuffer_len], dword BUFFERSIZE jl.urn call myio_flush.urn: popa Larrys buffered IO library ; myio_read_char ; fetch next char (in eax) from input buffer, ; fill if necessary global myio_read_char myio_read_char: push esi push edi push edx mov eax, 0 mov edx, [myio_ibuffer_len] cmp edx, 0 jg.fetch_next_char_from_buffer ; fill buffer mov [myio_ibuffer_idx], dword 0 sys_read STDIN, myio_ibuffer, BUFFERSIZE mov edx, eax cmp eax, 0 je.urn.fetch_next_char_from_buffer: mov esi, myio_ibuffer add esi, [myio_ibuffer_idx] mov eax, 0 mov al, [esi] add [myio_ibuffer_idx], dword 1 dec edx mov [myio_ibuffer_len], edx.urn: pop edx pop edi pop esi
276 !
277
278 Friday
279 seems like I don t need it before next month anyway Friday
280 Friday seems like I don t need it before next month anyway eat flaming death!
64-Bit NASM Notes. Invoking 64-Bit NASM
64-Bit NASM Notes The transition from 32- to 64-bit architectures is no joke, as anyone who has wrestled with 32/64 bit incompatibilities will attest We note here some key differences between 32- and 64-bit
About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer
About the Tutorial Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming
Assembly Language Tutorial
Assembly Language Tutorial ASSEMBLY LANGUAGE TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Assembly Programming Tutorial Assembly language is a low-level programming language for
For a 64-bit system. I - Presentation Of The Shellcode
#How To Create Your Own Shellcode On Arch Linux? #Author : N3td3v!l #Contact-mail : [email protected] #Website : Nopotm.ir #Spcial tnx to : C0nn3ct0r And All Honest Hackerz and Security Managers I - Presentation
Buffer Overflows. Security 2011
Buffer Overflows Security 2011 Memory Organiza;on Topics Kernel organizes memory in pages Typically 4k bytes Processes operate in a Virtual Memory Space Mapped to real 4k pages Could live in RAM or be
Abysssec Research. 1) Advisory information. 2) Vulnerable version
Abysssec Research 1) Advisory information Title Version Discovery Vendor Impact Contact Twitter CVE : Apple QuickTime FlashPix NumberOfTiles Remote Code Execution Vulnerability : QuickTime player 7.6.5
REpsych. : psycholigical warfare in reverse engineering. def con 2015 // domas
REpsych : psycholigical warfare in reverse engineering { def con 2015 // domas Warning This serves no purpose Taking something apart to figure out how it works With software Interfacing Documentation Obsolescence
Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc WwW.Abysssec.Com
Format string exploitation on windows Using Immunity Debugger / Python By Abysssec Inc WwW.Abysssec.Com For real beneficiary this post you should have few assembly knowledge and you should know about classic
A Tiny Guide to Programming in 32-bit x86 Assembly Language
CS308, Spring 1999 A Tiny Guide to Programming in 32-bit x86 Assembly Language by Adam Ferrari, [email protected] (with changes by Alan Batson, [email protected] and Mike Lack, [email protected])
Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail
Hacking Techniques & Intrusion Detection Ali Al-Shemery arabnix [at] gmail All materials is licensed under a Creative Commons Share Alike license http://creativecommonsorg/licenses/by-sa/30/ # whoami Ali
8. MACROS, Modules, and Mouse
8. MACROS, Modules, and Mouse Background Macros, Modules and the Mouse is a combination of concepts that will introduce you to modular programming while learning how to interface with the mouse. Macros
CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 20: Stack Frames 7 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Where We Are Source code if (b == 0) a = b; Low-level IR code
Off-by-One exploitation tutorial
Off-by-One exploitation tutorial By Saif El-Sherei www.elsherei.com Introduction: I decided to get a bit more into Linux exploitation, so I thought it would be nice if I document this as a good friend
Introduction. Figure 1 Schema of DarunGrim2
Reversing Microsoft patches to reveal vulnerable code Harsimran Walia Computer Security Enthusiast 2011 Abstract The paper would try to reveal the vulnerable code for a particular disclosed vulnerability,
Lecture 27 C and Assembly
Ananda Gunawardena Lecture 27 C and Assembly This is a quick introduction to working with x86 assembly. Some of the instructions and register names must be check for latest commands and register names.
esrever gnireenigne tfosorcim seiranib
esrever gnireenigne tfosorcim seiranib Alexander Sotirov [email protected] CanSecWest / core06 Reverse Engineering Microsoft Binaries Alexander Sotirov [email protected] CanSecWest / core06 Overview
Jorix kernel: real-time scheduling
Jorix kernel: real-time scheduling Joris Huizer Kwie Min Wong May 16, 2007 1 Introduction As a specialized part of the kernel, we implemented two real-time scheduling algorithms: RM (rate monotonic) and
Systems Design & Programming Data Movement Instructions. Intel Assembly
Intel Assembly Data Movement Instruction: mov (covered already) push, pop lea (mov and offset) lds, les, lfs, lgs, lss movs, lods, stos ins, outs xchg, xlat lahf, sahf (not covered) in, out movsx, movzx
Assembly Language: Function Calls" Jennifer Rexford!
Assembly Language: Function Calls" Jennifer Rexford! 1 Goals of this Lecture" Function call problems:! Calling and returning! Passing parameters! Storing local variables! Handling registers without interference!
Software Fingerprinting for Automated Malicious Code Analysis
Software Fingerprinting for Automated Malicious Code Analysis Philippe Charland Mission Critical Cyber Security Section October 25, 2012 Terms of Release: This document is approved for release to Defence
Introduction to Reverse Engineering
Introduction to Reverse Engineering Inbar Raz Malware Research Lab Manager December 2011 What is Reverse Engineering? Reverse engineering is the process of discovering the technological principles of a
Return-oriented programming without returns
Faculty of Computer Science Institute for System Architecture, Operating Systems Group Return-oriented programming without urns S. Checkoway, L. Davi, A. Dmitrienko, A. Sadeghi, H. Shacham, M. Winandy
Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD
BCD (ASCII) Arithmetic The Intel Instruction set can handle both packed (two digits per byte) and unpacked BCD (one decimal digit per byte) We will first look at unpacked BCD Unpacked BCD can be either
High-speed image processing algorithms using MMX hardware
High-speed image processing algorithms using MMX hardware J. W. V. Miller and J. Wood The University of Michigan-Dearborn ABSTRACT Low-cost PC-based machine vision systems have become more common due to
TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com
TitanMist: Your First Step to Reversing Nirvana TitanMist mist.reversinglabs.com Contents Introduction to TitanEngine.. 3 Introduction to TitanMist 4 Creating an unpacker for TitanMist.. 5 References and
Programming from the Ground Up. Jonathan Bartlett
Programming from the Ground Up Jonathan Bartlett Programming from the Ground Up by Jonathan Bartlett Copyright 2002 by Jonathan Bartlett Permission is granted to copy, distribute and/or modify this document
CPU performance monitoring using the Time-Stamp Counter register
CPU performance monitoring using the Time-Stamp Counter register This laboratory work introduces basic information on the Time-Stamp Counter CPU register, which is used for performance monitoring. The
Syscall Proxying - Simulating remote execution Maximiliano Caceres <[email protected]> Copyright 2002 CORE SECURITY TECHNOLOGIES
Syscall Proxying - Simulating remote execution Maximiliano Caceres Copyright 2002 CORE SECURITY TECHNOLOGIES Table of Contents Abstract.........................................................................................
CS61: Systems Programing and Machine Organization
CS61: Systems Programing and Machine Organization Fall 2009 Section Notes for Week 2 (September 14 th - 18 th ) Topics to be covered: I. Binary Basics II. Signed Numbers III. Architecture Overview IV.
Introduction to MIPS Assembly Programming
1 / 26 Introduction to MIPS Assembly Programming January 23 25, 2013 2 / 26 Outline Overview of assembly programming MARS tutorial MIPS assembly syntax Role of pseudocode Some simple instructions Integer
How Compilers Work. by Walter Bright. Digital Mars
How Compilers Work by Walter Bright Digital Mars Compilers I've Built D programming language C++ C Javascript Java A.B.E.L Compiler Compilers Regex Lex Yacc Spirit Do only the easiest part Not very customizable
Introduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
Computer Organization and Assembly Language
Computer Organization and Assembly Language Lecture 8 - Strings and Arrays Introduction We already know that assembly code will execute significantly faster than code written in a higher-level language
X86-64 Architecture Guide
X86-64 Architecture Guide For the code-generation project, we shall expose you to a simplified version of the x86-64 platform. Example Consider the following Decaf program: class Program { int foo(int
HC12 Assembly Language Programming
HC12 Assembly Language Programming Programming Model Addressing Modes Assembler Directives HC12 Instructions Flow Charts 1 Assembler Directives In order to write an assembly language program it is necessary
Attacking x86 Windows Binaries by Jump Oriented Programming
Attacking x86 Windows Binaries by Jump Oriented Programming L. Erdődi * * Faculty of John von Neumann, Óbuda University, Budapest, Hungary [email protected] Abstract Jump oriented programming
The Plan Today... System Calls and API's Basics of OS design Virtual Machines
System Calls + The Plan Today... System Calls and API's Basics of OS design Virtual Machines System Calls System programs interact with the OS (and ultimately hardware) through system calls. Called when
Heap-based Buffer Overflow Vulnerability in Adobe Flash Player
Analysis of Zero-Day Exploit_Issue 03 Heap-based Buffer Overflow Vulnerability in Adobe Flash Player CVE-2014-0556 20 December 2014 Table of Content Overview... 3 1. CVE-2014-0556 Vulnerability... 3 2.
The programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
Under The Hood: The System Call
2 Under The Hood: The System Call In this note, we ll peak under the hood of one simple and neat OS called xv6 [CK+08]. The xv6 kernel is a port of an old UNIX version 6 from PDP-11 (the machine it was
Faculty of Engineering Student Number:
Philadelphia University Student Name: Faculty of Engineering Student Number: Dept. of Computer Engineering Final Exam, First Semester: 2012/2013 Course Title: Microprocessors Date: 17/01//2013 Course No:
Instruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects
Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code
Introduction Application Security Tom Chothia Computer Security, Lecture 16 Compiled code is really just data which can be edit and inspected. By examining low level code protections can be removed and
1. General function and functionality of the malware
1. General function and functionality of the malware The malware executes in a command shell, it begins by checking to see if the executing file contains the MZP file extension, and then continues to access
Stack Overflows. Mitchell Adair
Stack Overflows Mitchell Adair Outline Why? What? There once was a VM Virtual Memory Registers Stack stack1, stack2, stack3 Resources Why? Real problem Real money Real recognition Still prevalent Very
Windows Assembly Programming Tutorial
JEFF HUANG ([email protected]) December 10, 2003 Windows Assembly Programming Tutorial Version 1.02 Copyright 2003, Jeff Huang. All rights reserved. by Jeff Huang Table of Contents Introduction... 2 Why
Fighting malware on your own
Fighting malware on your own Vitaliy Kamlyuk Senior Virus Analyst Kaspersky Lab [email protected] Why fight malware on your own? 5 reasons: 1. Touch 100% of protection yourself 2. Be prepared
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP2e Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, pushl, ret, How instructions
Character Translation Methods
Supplement to: Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition. This file may be duplicated or printed for classroom use, as long as the author name, book title, and copyright notice
Programming from the Ground Up
Programming from the Ground Up Jonathan Bartlett Edited by Dominick Bruno, Jr. Programming from the Ground Up by Jonathan Bartlett Edited by Dominick Bruno, Jr. Copyright 2003 by Jonathan Bartlett Permission
Wrestling with Python Unit testing. Warren Viant
Wrestling with Python Unit testing Warren Viant Assessment criteria OCR - 2015 Programming Techniques (12 marks) There is an attempt to solve all of the tasks using most of the techniques listed. The techniques
Overview of IA-32 assembly programming. Lars Ailo Bongo University of Tromsø
Overview of IA-32 assembly programming Lars Ailo Bongo University of Tromsø Contents 1 Introduction... 2 2 IA-32 assembly programming... 3 2.1 Assembly Language Statements... 3 2.1 Modes...4 2.2 Registers...4
Using MMX Instructions to Convert RGB To YUV Color Conversion
Using MMX Instructions to Convert RGB To YUV Color Conversion Information for Developers and ISVs From Intel Developer Services www.intel.com/ids Information in this document is provided in connection
Analysis of Win32.Scream
Analysis of Win32.Scream 1. Introduction Scream is a very interesting virus as it combines a lot of techniques written inside of it. In this paper I ll cover all of its features and internals. I ll dissect
CSC230 Getting Starting in C. Tyler Bletsch
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly
What Happens In Windows 7 Stays In Windows 7
What Happens In Windows 7 Stays In Windows 7 Moti Joseph & Marion Marschalek Troopers Conference 2014 About Us Joseph Moti Security Researcher Marion Marschalek Malware Analyst 8 7 3 1-7 3 6 4-1 9 3 2-9
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
TECHNICAL BULLETIN [ 1 / 5 ]
TECHNICAL BULLETIN [ 1 / 5 ] [Title] Corrective action when MELSOFT products cannot be installed on a personal computer on which the 6th Generation Intel Core Processor has been installed [Date of Issue]
Intel 8086 architecture
Intel 8086 architecture Today we ll take a look at Intel s 8086, which is one of the oldest and yet most prevalent processor architectures around. We ll make many comparisons between the MIPS and 8086
QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1
QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For
x64 Cheat Sheet Fall 2015
CS 33 Intro Computer Systems Doeppner x64 Cheat Sheet Fall 2015 1 x64 Registers x64 assembly code uses sixteen 64-bit registers. Additionally, the lower bytes of some of these registers may be accessed
Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: [email protected] Alfonso Ortega: alfonso.ortega@uam.
Compilers Spring term Mick O Donnell: [email protected] Alfonso Ortega: [email protected] Lecture 1 to Compilers 1 Topic 1: What is a Compiler? 3 What is a Compiler? A compiler is a computer
PC Assembly Language. Paul A. Carter
PC Assembly Language Paul A. Carter November 20, 2001 Copyright c 2001 by Paul Carter This may be reproduced and distributed in its entirety (including this authorship, copyright and permission notice),
Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas
Syscall 5 System call 5 allows input of numerical data from the keyboard while a program is running. Syscall 5 is a bit unusual, in that it requires the use of register $v0 twice. In syscall 5 (as for
Software Vulnerabilities
Software Vulnerabilities -- stack overflow Code based security Code based security discusses typical vulnerabilities made by programmers that can be exploited by miscreants Implementing safe software in
W4118 Operating Systems. Junfeng Yang
W4118 Operating Systems Junfeng Yang Outline Linux overview Interrupt in Linux System call in Linux What is Linux A modern, open-source OS, based on UNIX standards 1991, 0.1 MLOC, single developer Linus
Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) [email protected] http://www.mzahran.com
CSCI-UA.0201-003 Computer Systems Organization Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) [email protected] http://www.mzahran.com Some slides adapted (and slightly modified)
Programming from the Ground Up
Programming from the Ground Up Jonathan Bartlett Edited by Dominick Bruno, Jr. Programming from the Ground Up by Jonathan Bartlett Edited by Dominick Bruno, Jr. Copyright 2003 by Jonathan Bartlett Permission
Simple C Programs. Goals for this Lecture. Help you learn about:
Simple C Programs 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command Preprocessor,
Compiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
Automatic Network Protocol Analysis
Gilbert Wondracek, Paolo M ilani C omparetti, C hristopher Kruegel and E ngin Kirda {gilbert,pmilani}@ seclab.tuwien.ac.at chris@ cs.ucsb.edu engin.kirda@ eurecom.fr Reverse Engineering Network Protocols
PHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery
PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code
Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection
USENIX Security Symposium 2014, San Diego, CA, USA Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research Institute for
How To Hack The Steam Voip On Pc Orchesterian Moonstone 2.5 (Windows) On Pc/Robert Kruber (Windows 2) On Linux 2.2.2 (Windows 3.5) On A Pc
ReVuln Ltd. http://revuln.com @revuln [email protected] Revision 3 STEAM VOIP SECURITY BY LUIGI AURIEMMA Overview and details about the security issues found in the Steam voice framework. TABLE OF CONTENTS
Violating Database - Enforced Security Mechanisms
Violating Database - Enforced Security Mechanisms Runtime Patching Exploits in SQL Server 2000: a case study Chris Anley [[email protected]] 18/06/2002 An NGSSoftware Insight Security Research (NISR)
Harnessing Intelligence from Malware Repositories
Harnessing Intelligence from Malware Repositories Arun Lakhotia and Vivek Notani Software Research Lab University of Louisiana at Lafayette [email protected], [email protected] 7/22/2015 (C) 2015
WLSI Windows Local Shellcode Injection. Cesar Cerrudo Argeniss (www.argeniss.com)
WLSI Windows Local Shellcode Injection Cesar Cerrudo Argeniss (www.argeniss.com) Overview _ Introduction _ Establishing a LPC connection _ Creating a shared section _ The technique _ Building an exploit
Randy Hyde s Win32 Assembly Language Tutorials (Featuring HOWL) #4: Radio Buttons
Randy Hyde s Win32 Assembly Language Tutorials Featuring HOWL #4: Radio Buttons In this fourth tutorial of this series, we ll take a look at implementing radio buttons on HOWL forms. Specifically, we ll
Cloud Security Is Not (Just) Virtualization Security
Mihai Christodorescu, Reiner Sailer, Douglas Lee Schales, Daniele Sgandurra, Diego Zamboni IBM Research Cloud Security Is Not (Just) Virtualization Security Virtualization Enables Many Security Applications
CPSC 226 Lab Nine Fall 2015
CPSC 226 Lab Nine Fall 2015 Directions. Our overall lab goal is to learn how to use BBB/Debian as a typical Linux/ARM embedded environment, program in a traditional Linux C programming environment, and
Self Protection Techniques in Malware
DSIE 10 5 th Doctoral lsymposium on Informatics Engineering i January 28 29, 2010 Porto, Portugal Self Protection Techniques in Malware Tiago Santos Overview Introduction Malware Types Why Self Protection?
Using the RDTSC Instruction for Performance Monitoring
Using the Instruction for Performance Monitoring http://developer.intel.com/drg/pentiumii/appnotes/pm1.htm Using the Instruction for Performance Monitoring Information in this document is provided in connection
PKI, Git and SVN. Adam Young. Presented by. Senior Software Engineer, Red Hat. License Licensed under http://creativecommons.org/licenses/by/3.
PKI, Git and SVN Presented by Adam Young Senior Software Engineer, Red Hat License Licensed under http://creativecommons.org/licenses/by/3.0/ Agenda Why git Getting started Branches Commits Why? Saved
Removing Sentinel SuperPro dongle from Applications and details on dongle way of cracking Shub-Nigurrath of ARTeam Version 1.
Removing Sentinel SuperPro dongle from Applications Shub-Nigurrath of ARTeam Version 1.0 September 2006 1. Abstract... 2 2. Possible approaches: emulations vs simulation... 3 2.1. How a dongle works...
Computer Organization and Architecture
Computer Organization and Architecture Chapter 11 Instruction Sets: Addressing Modes and Formats Instruction Set Design One goal of instruction set design is to minimize instruction length Another goal
Chapter 7D The Java Virtual Machine
This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly
sys socketcall: Network systems calls on Linux
sys socketcall: Network systems calls on Linux Daniel Noé April 9, 2008 The method used by Linux for system calls is explored in detail in Understanding the Linux Kernel. However, the book does not adequately
How To Use A Computer With A Screen On It (For A Powerbook)
page 44,100 TITLE ASMXMPLE Video equ 10h ;video functions interrupt number Keyboard equ 16h ;keyboard functions interrupt number DOS equ 21h ;call DOS interrupt number PrtSc equ 5h ;Print Screen Bios interrupt
TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the 8086. Pointers and data storage in memory
Mitglied der Zürcher Fachhochschule TIn 1: Lecture 3 The Belly of the Architect. Lecture 3: Lernziele Basic internal components of the 8086 Pointers and data storage in memory Architektur 8086 Besteht
http://www.nologin.org Bypassing Windows Hardware-enforced Data Execution Prevention
http://www.nologin.org Bypassing Windows Hardware-enforced Data Execution Prevention Oct 2, 2005 skape [email protected] Skywing [email protected] One of the big changes that Microsoft introduced
PIC Programming in Assembly. (http://www.mstracey.btinternet.co.uk/index.htm)
PIC Programming in Assembly (http://www.mstracey.btinternet.co.uk/index.htm) Tutorial 1 Good Programming Techniques. Before we get to the nitty gritty of programming the PIC, I think now is a good time
Hacking the Preboot execution Environment
Hacking the Preboot execution Environment Using the BIOS network stack for other purposes Julien Vanegue [email protected] CESAR Recife Center for Advanced Studies and Systems, Brasil. September 27, 2008
