You are on page 1of 109

CMSC 216 Introduction to Computer Systems Assembly II

CMSC 216 - Slides developed by Wood, Sussman, Herman, Plane, and other UMCP CS faculty.

Announcements
Start reading Bryant and OHallaron Chapter 3 (IA-32 instruction set architecture) and 4.1 (Y86 subset)

Y86 integer instructions


Instruction
addl S,D subl S,D andl S,D xorl S,D multl S,D divl S,D modl S,D

Effect
Reg[D] Reg[D] + Reg[S] Reg[D] Reg[D] - Reg[S] Reg[D] Reg[D] & Reg[S] Reg[D] Reg[D] ^ Reg[S] Reg[D] Reg[D] * Reg[S] Reg[D] Reg[D] / Reg[S] Reg[D] Reg[D] % Reg[S]

Description
Addition Subtract Bitwise AND Bitwise XOR Multiplication* Integer division* Remainder*

Example
addl %eax,%ebx subl %eax,%ebx andl %eax,%ebx xor %eax,%ebx multl %eax,%ebx divl %eax,%ebx modl %eax,%ebx

All these instructions operate on two integers, and set the condition code flags appropriately Example: irmovl $2,%eax irmovl $8,%ebx divl %eax, %ebx # %ebx will have 4 Notice that only registers are used Instructions marked with an asterisk (*) are extensions to Y86 we've added to the ones in the book
3

Integer instruction example


Example: divl.ys Assembler output:
0x000: 0x006: 0x00c: 0x00e: 0x010: 0x016: 0x018: 0x01a: 0x020: 0x022: 308002000000 308308000000 6503 f308 308120000000 f118 f338 30810a000000 f118 10 | | | | | | | | | | irmovl irmovl divl wrint irmovl wrch wrint irmovl wrch halt $2,%eax $8,%ebx %eax,%ebx %eax $32,%ecx %ecx %ebx $10,%ecx %ecx # # # # # # # # a = 2 b = 8 b = b / a printing a 32 == ' ' printing space printing b 10 == '\n'

Simulator run: 24 ...

Notice these instructions are destructive; they overwrite the second operand Need to make copies if you need old values
4

Condition codes
Performing integer operations causes various flags to be set, describing the attributes of the result of the operation These are used by other, subsequent instructions to perform conditional branching The three we are concerned with are: OF: overflow flag; did the operation overflow? SF: sign flag; is the result negative? ZF: zero flag; is the result zero?

Branch instructions
These are used to perform the effect of if statements, loops, and switches When encountered, if a certain condition is true, control flow will then go to the address specified, rather than advancing to the next instruction The address of the next instruction to be executed is held in the program counter; in many architectures, this is held in an accessible register (not so with Y86). Labels We use labels (name followed by colon) to represent target addresses When the assembler encounters a label (e.g., Loop:), the address of the labeled instruction is used by the assembler to replace all references to that label in the program Labels do not need to be declared before use
6

Y86 branch instructions


Instruction jmp Label jle Label jl je Label Label Branch if... 1 (SF ^ OF) | ZF SF ^ OF ZF ~ZF ~(SF ^ OF) ~(SF ^ OF) & ~ZF Description Unconditional jump Jump if less than or equal to zero Jump if less than zero Jump if equal to zero Jump if not equal to zero Jump if greater than or equal to zero Jump if greater than zero

jne Label jge Label jg Label

Each instruction relies on the condition codes set by the most recent integer instruction

Translating branches
Since assembly has no else statements, we need to use branching + code reorganization to get if/else Consider the following C code: if (a == b) printf(Y"); else printf(N"); printf("\n"); if (a == b) goto Equal; printf(N"); goto EndIf; Equal: printf(Y"); EndIf: printf("\n");

Translating branches, cont.


We can then take the labeled C code and translate it in a fairly straightforward fashion: Example: If.ys Assembler Output
0x000: 0x002: 0x004: 0x006: 0x00b: 0x011: 0x013: 0x018: 0x01e: 0x020: 0x026: 0x028: f208 f238 6130 7318000000 30814e000000 f118 7020000000 308159000000 f118 30820a000000 f128 10 | rdint %eax | rdint %ebx | subl %ebx, %eax | je Equal | irmovl $78, %ecx | wrch %ecx | jmp EndIf | Equal: irmovl $89, %ecx | wrch %ecx | EndIf: irmovl $10, %edx | wrch %edx | halt # reading a # reading b # we are overwriting %eax
# else block, 78 --> N

# true block case, 89 --> Y # 10 --> newline

Branch Example
Example: If2.ys if (a >= b) print a else print b Assembler output:
0x000: 0x002: 0x004: 0x006: 0x008: 0x00d: 0x00f: 0x014: 0x016: 0x01c: 0x01e: f208 f238 2001 6131 7514000000 f338 7016000000 f308 30820a000000 f128 10 | rdint %eax | rdint %ebx | rrmovl %eax, %ecx | subl %ebx, %ecx | jge Equal | wrint %ebx | jmp EndIf | Equal: wrint %eax | EndIf: irmovl $10, %edx | wrch %edx | halt # # # # reading a reading b making copy of %eax no longer overwriting %eax

# else block # true block # newline

Simulator output:
4 3 4 Stopped in 9 steps at PC = 0x1f. Exception 'HLT', CC Z=0 S=0 O=0

10

Translating C to Y86
This process is not always straightforward Even simple statements like c = a * b;" can require several instructions:
mrmovl A, %eax mrmovl B, %ebx multl %eax, %ebx rmmovl %ebx, C

11

Register spilling
We only have a limited number of registers What happens if we need to keep more than 8 values around at once? If we run out of registers to store our data, we need to use memory to store values We can use the stack or define static arrays (as we'll see later)

12

Translating loops
What about C code like this? do { ... } while (condition); This can be translated simply: Loop: # begin loop body # evaluate condition jumpCondition Loop # jump back if true Note that you can use whatever jumpCondition (e.g., jle, je, etc.) instruction/condition is appropriate Example: doWhile.ys

13

do While Example
Example: doWhile.ys Assembler output:
0x000: f208 | 0x002: 308301000000 | 0x008: 308101000000 | | 0x00e: f338 | Loop: 0x010: 308220000000 | 0x016: f128 | | 0x018: 6013 | 0x01a: 2032 | 0x01c: 6102 | 0x01e: 710e000000 | | 0x023: 30820a000000 | EndLoop: 0x029: f128 | 0x02b: 10 | rdint %eax irmovl $1, %ebx irmovl $1, %ecx
wrint %ebx irmovl $32, %edx wrch %edx addl %ecx, %ebx rrmovl %ebx, %edx subl %eax, %edx jle Loop irmovl $10, %edx wrch %edx halt

# loop limit # iteration variable # increment


# writing value # printing blank character

# incrementing by 1 # making copy # jump back # newline character

Simulator output:
Exception 'HLT', CC Z=0 S=0 O=0

5 1 2 3 4 5 Stopped in 41 steps at PC = 0x2c.

14

Translating while loops


while loops are a bit different; but these can be written as do-while loops, with a little modification while (cond) { task(); } if (cond) { do { task(); } while(condition); }

eval cond jump EndLoop if !cond Loop: task() eval cond jump to Loop if cond EndLoop:

if (!cond) { jump EndLoop } do { task() } while(cond): EndLoop:


15

while Example
Example: while.ys Assembler output:

0x000: f208 | 0x002: 308301000000 | 0x008: 308101000000 | | 0x00e: 2032 | 0x010: 6102 | 0x012: 762c000000 | | 0x017: f338 | Loop: 0x019: 308620000000 | 0x01f: f168 | | 0x021: 6013 | 0x023: 2032 | 0x025: 6102 | 0x027: 7117000000 | | 0x02c: 30810a000000 | EndLoop: 0x032: f118 | 0x034: 10 |
Simulator output: 3 1 2 3 Stopped in 30 steps at PC = 0x35.

rdint %eax irmovl $1, %ebx irmovl $1, %ecx rrmovl %ebx, %edx subl %eax, %edx jg EndLoop

# loop limit # iteration variable # increment variable

wrint %ebx irmovl $32, %esi wrch %esi


addl %ecx, %ebx rrmovl %ebx, %edx subl %eax, %edx jle Loop irmovl $10, %ecx wrch %ecx halt

# writing value # printing blank character

# incrementing by 1

# newline character

Exception 'HLT', CC Z=0 S=0 O=0

16

Translating for loops


For loops are very similar to while loops; we can use this fact to convert a for loop into a form we know how to work with How do we convert this into a while loop? for (init; cond; incr) body;
init; while (cond) { body; incr; }

17

Examples
Example: sum.ys Example: arraySum.ys

18

Factorial example
Consider the following program:
#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; while (i <= n) f *= i++; printf("%d\n", f); return 0; }

How would we convert this to a Y86 program?


19

Translating our factorial example


Because we only have three variables, we can get away with doing all our work in registers, rather than storing things in memory The scanf() and printf() calls can be easily replaced by rdint and wrint/wrch instructions The main work involved here is just translating the while loop to the do-while format we need to convert to assembly

20

Translated into goto-code


#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; if (i > n) goto EndWhile; Loop: f *= i++; if (i <= n) goto Loop; EndWhile: printf("%d\n", f); return 0; }
21

Breaking apart compound statements


#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; if (i > n) goto EndWhile; Loop: f *= i++; if (i <= n) goto Loop; EndWhile: printf("%d\n", f); return 0; }
22

Breaking apart compound statements


#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; if (i > n) goto EndWhile; Loop: f = f * i++; if (i <= n) goto Loop; EndWhile: printf("%d\n", f); return 0; }
23

Breaking apart compound statements


#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; if (i > n) goto EndWhile; Loop: f = f * i; i = i + 1; if (i <= n) goto Loop; EndWhile: printf("%d\n", f); return 0; }

24

Beginning "compilation"
We'll map registers to variables: %eax for i, %ebx for f, and %ecx for n Remember why we can do this here? Now, let's translate all the non-branches into the assembly code we know.

25

Starting compilation
#include <stdio.h> int main() { int i, f, n; scanf("%d", &n); f = 1; i = 1; if (i > n) goto EndWhile; Loop: f = f * i; i = i + 1; if (i <= n) goto Loop; EndWhile: printf("%d\n", f); return 0; } rdint %ecx irmovl $1,%ebx irmovl $1,%eax if (%eax > %ecx) goto EndWhile; Loop: multl %eax,%ebx irmovl $1,%edi addl %edi,%eax if (%eax <= %ecx) goto Loop;

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt

26

Writing branches
To change the conditional jumps, we'll have to remember a few things: we'll need to operate on copies of our data; this means we'll need to use an extra register we'll need to perform an arithmetic operation before the jump we need to select the correct jump instruction to operate correctly
27

Starting compilation
rdint %ecx irmovl $1,%ebx irmovl $1,%eax if (%eax > %ecx) goto EndWhile; Loop: multl %eax,%ebx irmovl $1,%edi addl %edi,%eax if (%eax <= %ecx) goto Loop; rdint irmovl irmovl rrmovl subl jg %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile

Loop:

multl %eax,%ebx irmovl $1,%edi addl %edi,%eax if (%eax <= %ecx) goto Loop;

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt

28

Starting compilation
rdint %ecx irmovl $1,%ebx irmovl $1,%eax if (%eax > %ecx) goto EndWhile; Loop: multl %eax,%ebx irmovl $1,%edi addl %edi,%eax if (%eax <= %ecx) goto Loop; rdint irmovl irmovl rrmovl subl jg %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile

Loop:

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt

multl irmovl addl rrmovl subl jle

%eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi Loop

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt


29

A working Y86 program (factorial.ys)


rdint irmovl irmovl rrmovl subl jg Loop: multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi Loop # # # # # # # # # # # # # # # # scanf("%d", &n); f = 1; i = 1; tmp = i; tmp -= n; if (tmp > 0) goto EndWhile; f *= i; tmp = 1; i += tmp; tmp = i; tmp -= n; if (tmp <= 0) goto Loop; printf("%d", f); tmp = '\n'; printf("%c", tmp); return 0;

EndWhile: wrint %ebx irmovl $10,%edi wrch %edi halt

30

Assembly
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: | | | | | | | 0x017: 6403 | Loop: 0x019: 308701000000 | 0x01f: 6070 | 0x021: 2007 | 0x023: 6117 | 0x025: 7117000000 | | 0x02a: f338 | EndWhile: 0x02c: 30870a000000 | 0x032: f178 | 0x034: 10 | f218 308301000000 308001000000 2007 6117 762a000000 rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi Loop

wrint %ebx irmovl $10,%edi wrch %edi halt

31

The program in memory


0x00: 0x08: 0x10: 0x18: 0x20: 0x28: 0x30: f2 30 61 03 70 00 00 18 80 17 30 20 00 00 30 01 76 87 07 f3 f1 83 00 2a 01 61 38 78 01 00 00 00 17 30 10 00 00 00 00 71 87 00 00 20 00 00 17 0a 00 00 07 64 60 00 00 00

32

Assembly
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: | | | | | | | 0x017: 6403 | Loop: 0x019: 308701000000 | 0x01f: 6070 | 0x021: 2007 | 0x023: 6117 | 0x025: 7117000000 | | 0x02a: f338 | EndWhile: 0x02c: 30870a000000 | 0x032: f178 | 0x034: 10 | f218 308301000000 308001000000 2007 6117 762a000000 rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi Loop

wrint %ebx irmovl $10,%edi wrch %edi halt

33

Assembly
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | Loop: | | | | | | | EndWhile: | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi EndWhile %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi Loop

wrint %ebx irmovl $10,%edi wrch %edi halt

34

Label Translation
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | Loop: | | | | | | | EndWhile: | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17

wrint %ebx irmovl $10,%edi wrch %edi halt

35

Final Factorial Program


0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | Loop: | | | | | | | EndWhile: | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17

wrint %ebx irmovl $10,%edi wrch %edi halt

36

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
0 0 0 0 0 0 0 PC 0x000 CC: ZF 0 CC: SF 0 CC: OF 0
37

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
0 0 0 0 0 0 0 PC 0x002 CC: ZF 0 CC: SF 0 CC: OF 0
38

Input is: 4

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
4 0 0 0 0 0 0 PC 0x002 CC: ZF 0 CC: SF 0 CC: OF 0
39

Input is: 4

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
4 0 0 0 0 0 0 PC 0x008 CC: ZF 0 CC: SF 0 CC: OF 0
40

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
4 0 1 0 0 0 0 PC 0x008 CC: ZF 0 CC: SF 0 CC: OF 0
41

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

0
4 0 1 0 0 0 0 PC 0x00e CC: ZF 0 CC: SF 0 CC: OF 0
42

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 0 PC 0x00e CC: ZF 0 CC: SF 0 CC: OF 0
43

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 0 PC 0x010 CC: ZF 0 CC: SF 0 CC: OF 0
44

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 1 PC 0x010 CC: ZF 0 CC: SF 0 CC: OF 0
45

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 1 PC 0x012 CC: ZF 0 CC: SF 0 CC: OF 0
46

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x012 CC: ZF 0 CC: SF 1 CC: OF 0
47

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x017 CC: ZF 0 CC: SF 1 CC: OF 0
48

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x017 CC: ZF 0 CC: SF 1 CC: OF 0
49

jg: ~(SF ^ OF) & ~ZF = 0

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x019 CC: ZF 0 CC: SF 1 CC: OF 0
50

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x019 CC: ZF 0 CC: SF 0 CC: OF 0
51

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 -3 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
52

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 1 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
53

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

1
4 0 1 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
54

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
55

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 1 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
56

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 2 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
57

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 2 PC 0x025 CC: ZF 0 CC: SF 0 CC: OF 0
58

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 -2 PC 0x025 CC: ZF 0 CC: SF 1 CC: OF 0
59

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 -2 PC 0x02a CC: ZF 0 CC: SF 1 CC: OF 0
60

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 -2 PC 0x017 CC: ZF 0 CC: SF 1 CC: OF 0
61

jle: (SF ^ OF) | ZF = 1

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 1 0 0 0 -2 PC 0x019 CC: ZF 0 CC: SF 1 CC: OF 0
62

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 2 0 0 0 -2 PC 0x019 CC: ZF 0 CC: SF 0 CC: OF 0
63

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 2 0 0 0 -2 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
64

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 2 0 0 0 1 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
65

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

2
4 0 2 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
66

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
67

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 1 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
68

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 3 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
69

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 3 PC 0x025 CC: ZF 0 CC: SF 0 CC: OF 0
70

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 -1 PC 0x025 CC: ZF 0 CC: SF 1 CC: OF 0
71

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 -1 PC 0x02a CC: ZF 0 CC: SF 1 CC: OF 0
72

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 -1 PC 0x017 CC: ZF 0 CC: SF 1 CC: OF 0
73

jle: (SF ^ OF) | ZF = 1

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 2 0 0 0 -1 PC 0x019 CC: ZF 0 CC: SF 1 CC: OF 0
74

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 6 0 0 0 -1 PC 0x019 CC: ZF 0 CC: SF 0 CC: OF 0
75

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 6 0 0 0 -1 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
76

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 6 0 0 0 1 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
77

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

3
4 0 6 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
78

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
79

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 1 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
80

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 4 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
81

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 4 PC 0x025 CC: ZF 0 CC: SF 0 CC: OF 0
82

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 0 PC 0x025 CC: ZF 1 CC: SF 0 CC: OF 0
83

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 0 PC 0x02a CC: ZF 1 CC: SF 0 CC: OF 0
84

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 0 PC 0x017 CC: ZF 1 CC: SF 0 CC: OF 0
85

jle: (SF ^ OF) | ZF = 1

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 6 0 0 0 0 PC 0x019 CC: ZF 0 CC: SF 1 CC: OF 0
86

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 24 0 0 0 0 PC 0x019 CC: ZF 0 CC: SF 0 CC: OF 0
87

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 24 0 0 0 0 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
88

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 24 0 0 0 1 PC 0x01f CC: ZF 0 CC: SF 0 CC: OF 0
89

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

4
4 0 24 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
90

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x021 CC: ZF 0 CC: SF 0 CC: OF 0
91

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
92

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 5 PC 0x023 CC: ZF 0 CC: SF 0 CC: OF 0
93

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 5 PC 0x025 CC: ZF 0 CC: SF 0 CC: OF 0
94

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x025 CC: ZF 0 CC: SF 0 CC: OF 0
95

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x02a CC: ZF 0 CC: SF 0 CC: OF 0
96

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x02a CC: ZF 0 CC: SF 0 CC: OF 0
97

jle: (SF ^ OF) | ZF = 0

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 1 PC 0x02c CC: ZF 0 CC: SF 0 CC: OF 0
98

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx Register $1,%ebx name Value $1,%eax %eax 5 %eax,%edi %ecx 4 %ecx,%edi %edx 0 0x2a %ebx 24 %eax,%ebx $1,%edi %esp 0 %edi,%eax %ebp 0 %eax,%edi %esi 0 %ecx,%edi %edi 1 0x17 %ebx PC 0x02c $10,%edi Output is: 24 CC: ZF 0 %edi
CC: SF 0 CC: OF 0
99

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx Register $1,%ebx name Value $1,%eax %eax 5 %eax,%edi %ecx 4 %ecx,%edi %edx 0 0x2a %ebx 24 %eax,%ebx $1,%edi %esp 0 %edi,%eax %ebp 0 %eax,%edi %esi 0 %ecx,%edi %edi 1 0x17 %ebx PC 0x032 $10,%edi Output is: 24 CC: ZF 0 %edi
CC: SF 0 CC: OF 0
100

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx Register $1,%ebx name Value $1,%eax %eax 5 %eax,%edi %ecx 4 %ecx,%edi %edx 0 0x2a %ebx 24 %eax,%ebx $1,%edi %esp 0 %edi,%eax %ebp 0 %eax,%edi %esi 0 %ecx,%edi %edi 10 0x17 %ebx PC 0x032 $10,%edi Output is: 24 CC: ZF 0 %edi
CC: SF 0 CC: OF 0
101

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx Register $1,%ebx name Value $1,%eax %eax 5 %eax,%edi %ecx 4 %ecx,%edi %edx 0 0x2a %ebx 24 %eax,%ebx $1,%edi %esp 0 %edi,%eax %ebp 0 %eax,%edi %esi 0 %ecx,%edi %edi 10 0x17 %ebx PC 0x034 $10,%edi Output is: 24 CC: ZF 0 %edi
CC: SF 0 CC: OF 0
102

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx Register $1,%ebx name Value $1,%eax %eax 5 %eax,%edi %ecx 4 %ecx,%edi %edx 0 0x2a %ebx 24 %eax,%ebx $1,%edi %esp 0 %edi,%eax %ebp 0 %eax,%edi %esi 0 %ecx,%edi %edi 10 0x17 %ebx PC 0x034 $10,%edi Output is: 24 CC: ZF 0 %edi
CC: SF 0 CC: OF 0
103

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 10 PC 0x035 CC: ZF 0 CC: SF 0 CC: OF 0
104

Execution
0x000: 0x002: 0x008: 0x00e: 0x010: 0x012: 0x017: 0x019: 0x01f: 0x021: 0x023: 0x025: 0x02a: 0x02c: 0x032: 0x034: | | | | | | | | | | | | | | | | rdint irmovl irmovl rrmovl subl jg multl irmovl addl rrmovl subl jle wrint irmovl wrch halt %ecx $1,%ebx $1,%eax %eax,%edi %ecx,%edi 0x2a %eax,%ebx $1,%edi %edi,%eax %eax,%edi %ecx,%edi 0x17 %ebx $10,%edi %edi
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 10 PC 0x035 CC: ZF 0

Done!

CC: SF 0 CC: OF 0
105

Execution
These are the final states of the PC, CC, and all the registers. Does this agree with what yis tells us? Remember, numbers are printed in hex, so 1010 = a16, 2410 = 1816
Register name Value

%eax
%ecx %edx %ebx %esp %ebp %esi %edi

5
4 0 24 0 0 0 10 PC 0x035 CC: ZF 0 CC: SF 0 CC: OF 0
106

Execution
Yes:
$ echo 4 | yis factorial.yo 24 Stopped in 34 steps at PC = 0x35. Exception 'HLT', CC Z=0 S=0 O=0 Changes to registers: %eax: 0x00000000 0x00000005 %ecx: 0x00000000 0x00000004 %ebx: 0x00000000 0x00000018 %edi: 0x00000000 0x0000000a Changes to memory:

107

Some other notes


Exceptions If your code exits due to a halt instruction, the exception will be HLT (which is fine) You can also stop your code prematurely by passing a second parameter (max steps) to yis; this will usually result in the exception AOK But if you manage to move to a bad address (forget to halt?), divide by zero, or just make the simulator otherwise unhappy, you'll get a different exception (e.g., ADR or INS)

108

Program efficiency
Our assembly program was not as efficient as it could be we could have optimized away the need for the variable i by simply decrementing n until n was 0 we also could have been smarter with our registers, and not overwritten the constant value we used repeatedly (1) These things need to be taken into consideration by compilers, and by you in the assembly code youre writing for the project...

109

You might also like