Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Chapter2a

225
views

Published on

Published in: Education, Technology

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
225
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
1
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Group Activity Sample: scanf(“%c”,&x); mov eax, 3 mov ebx, 0 mov ecx, x int 80h
• 2. Group Activity 1. printf(“%c”,x); 2. sum = x + y; 3. prod = x * y; (assume x and y are byte-size variables)
• 3. Group Activity 1. printf(“%c”,x); mov eax, 4 mov ebx, 1 mov ecx, x mov edx, 1 int 80h
• 4. Group Activity 2. sum = x + y; mov bl, [x] add bl, [y] mov [sum], bl
• 5. Group Activity 3. prod = x * y; mov al, [x] mul byte[y] mov [prod], ax
• 6. Structured Assembly LanguageProgramming TechniquesControl Transfer Instructions
• 7. Objectives At the end of the discussion, the students should be able to:  Implement selection statements in assembly  Describe how unconditional jumps and conditional statements work
• 8. Control Transfer Instructions  allows program control to transfer to specified label  Unconditional or Conditional  Unconditional – executed without regards to any situation or condition in the program – transfer of control goes from one code to another by force jmp label – unconditional jump
• 9. Control Transfer Instructions mov al, 5 next: add [num1],al mov eax, 4 jmp next mov ebx, 1 mov ecx, num2 mov eax, 4 mov edx, 1 mov ebx, 1 int 80h mov ecx, num1 mov edx, 1 int 80h (1) (2)
• 10. Control Transfer Instructions  Conditional – a jump carried out on the basis of a truth value – the information on which such decisions are based is contained in the flags registers
• 11. Boolean Expressions  evaluates to True or False  compares two values  cmp source1, source2  Source1 may be a register or memory  Source2 may be a register, memory or immediate  Operands cannot be both memory.  Operands must be of the same size.
• 12. Conditional Jumps  usually placed after a cmp instruction conditional_jump label  JE – branches if source1 == source2  JNE – branches if source1 ≠ source2
• 13. Conditional Jumps  Signed Conditional Jump – JL or JNGE  branches if source1 < source2 – JLE or JNG  branches if source1 ≤ source2 – JG or JNLE  branches if source1 > source2 – JGE or JNL  branches if source1 ≥ source2
• 14. Conditional Jumps  Unsigned Conditional Jumps – JB or JNAE  branches if source1 < source2 – JBE or JNA  branches if source1 ≤ source2 – JA or JNBE  branches if source1 > source2 – JAE or JNB  branches if source1 ≥ source2
• 15. Control Structure: IF Statement if (boolean) cmp AX, CX {statements;} jg if_statement jmp next_statement if(AX>CX){ BX = DX + 2; if_statement: } add DX, 2 mov BX, DX next_statement: ...