Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Carter P.A.PC assembly language.2005.pdf
Скачиваний:
16
Добавлен:
23.08.2013
Размер:
1.07 Mб
Скачать

42

CHAPTER 2. BASIC ASSEMBLY LANGUAGE

sum = 0;

for ( i=10; i >0; i−− ) sum += i;

could be translated into assembly as:

1

mov

eax,

0

;

eax

is

sum

2

mov

ecx,

10

;

ecx

is

i

3loop_start:

4

add

eax, ecx

5loop loop_start

2.3Translating Standard Control Structures

This section looks at how the standard control structures of high level languages can be implemented in assembly language.

2.3.1If statements

The following pseudo-code:

if ( condition ) then block ;

else

else block ;

could be implemented as:

1; code to set FLAGS

2

jxx

else_block

; select xx so that branches if condition false

3; code for then block

4

jmp

endif

5else_block:

6; code for else block

7endif:

If there is no else, then the else block branch can be replaced by a branch to endif.

1

2

3

; code

to set FLAGS

 

jxx

endif

; select xx so that branches if condition false

; code

for then block

 

4endif:

Соседние файлы в предмете Электротехника