1. Trang chủ
  2. » Trung học cơ sở - phổ thông

Lecture Computer organization and assembly language - Lecture 20: Conditional and Block Structures - TRƯỜNG CÁN BỘ QUẢN LÝ GIÁO DỤC THÀNH PHỐ HỒ CHÍ MINH

10 15 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 117,01 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

– JNE, JNZ jump to a label if the Zero flag is clear – JECXZ jumps to a label if ECX equals 0. • Assembly Examples[r]

Trang 1

CSC 221

Computer Organization and Assembly

Language

Lecture 20:

Conditional and Block Structures

Trang 2

Lecture 19: Review

I/O Instructions

StdIn proc lpszBuffer:DWORD,bLen:DWORD

StdOut proc lpszText:DWORD

invoke StdOut, addr message1

invoke StdIn, addr buffer, 100

Conditional Jumps

– Specific flags

– Equality

– Unsigned comparisons

– Signed Comparisons

Trang 3

Lecture 19: Review

Conditional Jumps

– JB, JC jump to a label if the Carry flag is set

– JE, JZ jump to a label if the Zero flag is set

– JS jumps to a label if the Sign flag is set

– JNE, JNZ jump to a label if the Zero flag is clear

– JECXZ jumps to a label if ECX equals 0

(cont.)

Trang 4

Lecture Outline

– LOOPZ and LOOPE

– LOOPNZ and LOOPNE

– Block-Structured IF Statements

– Compound Expressions with AND

– Compound Expressions with OR

– WHILE Loops

– REPEAT Loops

Trang 5

BT (Bit Test) Instruction

• Copies bit n from an operand into the Carry flag

• Syntax: BT bitBase, n

– n may be r16, r32, or imm8

• Example: jump to label L1 if bit 9 is set in the AX register:

Carry

Trang 6

Conditional Loop Instructions

Trang 7

LOOPZ and LOOPE

• Syntax:

LOOPE destination

LOOPZ destination

• Logic:

– ECX ECX – 1

if ECX > 0 and ZF=1, jump to destination

• Useful when scanning an array for the first element that does not match a given value

Trang 8

LOOPNZ and LOOPNE

• LOOPNZ (LOOPNE) is a conditional loop instruction

• Syntax:

LOOPNZ destination LOOPNE destination

• Logic:

– ECX ECX – 1;

if ECX > 0 and ZF=0, jump to destination

• Useful when scanning an array for the first element that matches a given value

Trang 9

LOOPNZ Example

.data

array SWORD -3,-6,-1,-10,10,30,40,4

sentinel SWORD 0

.code

mov esi,OFFSET array

mov ecx,LENGTHOF array

next:

stack

add esi,TYPE array

stack

value

quit:

The following code finds the first positive value in an array:

Trang 10

Drill

.data

array SWORD 50 DUP(?)

sentinel SWORD 0FFFFh

.code

mov esi,OFFSET array

mov ecx,LENGTHOF array

(fill in your code here)

quit:

Locate the first nonzero value in the array If none is found, let ESI point to the sentinel value:

Ngày đăng: 01/04/2021, 16:33

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w