Будь умным!


У вас вопросы?
У нас ответы:) SamZan.net

по теме SSEMBLER LNGUGE для студентов специальности 145 01 03 ' Сети телекоммуникаций специализации 145 01 03 04

Работа добавлена на сайт samzan.net: 2016-03-05

Поможем написать учебную работу

Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.

Предоплата всего

от 25%

Подписываем

договор

Выберите тип работы:

Скидка 25% при заказе до 17.5.2024

МИНИСТЕРСТВО СВЯЗИ И ИНФОРМАТИЗАЦИИ

РЕСПУБЛИКИ БЕЛАРУСЬ

Учреждение образования

«ВЫСШИЙ ГОСУДАРСТВЕННЫЙ КОЛЛЕДЖ СВЯЗИ»

Кафедра гуманитарных наук

английский язык

Практикум

для развития навыков технического перевода,

чтения и устной речи

по теме

«ASSEMBLER LANGUAGE»

для студентов специальности

1-45 01 03 – Сети телекоммуникаций

специализации

1-45 01 03 04 – Программное обеспечение сетей телекоммуникаций

В 2 частях

Часть 1

Минск

2009


УДК 811.1

ББК 81.2 Англ.

А64

Рекомендовано к изданию кафедрой гуманитарных наук

апреля 2009, протокол №

Составитель 

Е. М. Игнатьева, доцент кафедры гуманитарных наук

Рецензент 

Т. Н. Самсонова, ст. преподаватель кафедры гуманитарных наук

А64

Английский язык : практикум для развития навыков технического перевода, чтения и устной речи по теме «ASSEMBLER» для студентов специальности 1-45 01 03 – Сети телекоммуникаций специализации 1-45 01 03 04 − Программное обеспечение сетей телекоммуникаций. В 2 ч. Ч. 1 / сост. Е. М. Игнатьева. – Минск : ВГКС, 2009. – с.

ISBN 978-985-6866-58-9.

Пособие предлагает выборку неадаптированных текстов, которые последовательно излагают и дополняют тематику цикла лекций по языку программирования ASSEMBLER.

Предназначено для студентов и преподавателей колледжа.

УДК 811.1

ББК 81.2Англ.

ISBN 

© Учреждение образования «Высший государственный колледж связи», 2009


Unit 1

1 Learn the following words and word-combinations.

access, v 

обращаться, иметь доступ

binary system

2-ная система исчисления

bit, n

Бит

byte, n

Байт

convert, v

конвертировать, преобразовывать

consider, v

рассматривать, обсуждать, полагать

data, n

данные, информация

decimal system

10-ная  система исчисления

device, n

Устройство

digit, n

Цифра

efficiently, adv

эффективно, продуктивно

encode, v

кодировать, закодировать

equivalent, n

эквивалент, равноценный

frequency, n

Частота

hexadecimal system

16-ная  система исчисления

label, v

помечать, отмечать

location, n

ячейка памяти

measure, v

измерять

perform, v

выполнять, совершать

power, n

степень

require, v

требовать, нуждаться

shift, v

перемещать, перестанавливать

significant, a

существенный, значимый

simplify, v

упрощать

store, v

хранить

unit, n

единица, часть, блок

2 Learn the following abbreviations

ASCII (American Standard Code for Information Interchange)Американский стандартный код преобразования информации;

CPU (Central Processing Unit) – ЦПУ (центральное процессорное устройство).

3 Read the texts and be ready to report on the following concepts:

1. «Memory»;

2. «The CPU».

Reading

Text 1 Number Systems

Memory in a computer consists of numbers. Computer memory does not store these numbers in decimal (base 10). Because it greatly simplifies the hardware, computers store all information in a binary (base 2) format. First let’s review the decimal system.

Decimal

Base 10 numbers are composed of 10 possible digits (0-9). Each digit of a number has a power of 10 associated with it based on its position in the number. For example:

234 = 2 × 102 + 3 × 101 + 4 × 100

Binary

Base 2 numbers are composed of 2 possible digits (0 and 1). Each digit of a number has a power of 2 associated with it based on its position in the number. (A single binary digit is called a bit.) For example:

110012 = 1 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 1 × 20

= 16 + 8 + 1

= 25

This shows how binary may be converted to decimal. Table 1.1 shows how the first few numbers are represented in binary.

Figure 1.1 shows how individual binary digits (i.e., bits) are added.

Here’s an example:

If one considers the following decimal division:

1234 ÷ 10 = 123 r 4

he can see that this division strips off the rightmost decimal digit of the number and shifts the other decimal digits one position to the right. Dividing by two performs a similar operation, but for the binary digits of the number.

Consider the following binary division1:

11012 ÷ 102 = 1102 r 1

This fact can be used to convert a decimal number to its equivalent binary representation as Figure 1.2 shows. This method finds the rightmost digit first, this digit is called the least significant bit (lsb). The leftmost digit is called the most significant bit (msb). The basic unit of memory consists of 8 bits and is called a byte.

Hexadecimal

Hexadecimal numbers use base 16. Hexadecimal (or hex for short) can be used as a shorthand for binary numbers. Hex has 16 possible digits. This creates a problem since there are no symbols to use for these extra digits after 9. By convention, letters are used for these extra digits. The 16 hex digits are 0-9 then A, B, C, D, E and F. The digit A is equivalent to 10 in decimal, B is 11, etc. Each digit of a hex number has a power of 16 associated with it. Example:

2BD16 = 2 × 162 + 11 × 161 + 13 × 160

= 512 + 176 + 13

= 701

Text 2 Computer Organization

Memory

The basic unit of memory is a byte. A computer with 32 megabytes Memory is measured in units of kilobytes  of memory can hold roughly 32 million bytes of information. Each byte in memory is labeled by a unique number known as its address as Figure 1.4 shows.

Often memory is used in larger chunks than single bytes. On the PC architecture, names have been given to these larger sections of memory as Table 1.2 shows.

All data in memory is numeric. Characters are stored by using a character code that maps numbers to characters. One of the most common character codes is known as ASCII (American Standard Code for Information Interchange). A new, more complete code that is supplanting ASCII is Unicode. One key difference between the two codes is that ASCII uses one byte to encode a character, but Unicode uses two bytes (or a word) per character. For example, ASCII maps the byte 4116 (6510) to the character capital A; Unicode maps the word 004116. Since ASCII uses a byte, it is limited to only 256 different characters3. Unicode extends the ASCII values to words and allows many more characters to be represented. This is important for representing characters for all the languages of the world.

The CPU

The Central Processing Unit (CPU) is the physical device that performs instructions. The instructions that CPUs perform are generally very simple. Instructions may require the data they act on to be in special storage locations in the CPU itself called registers. The CPU can access data in registers much faster than data in memory. However, the number of registers in a CPU is limited, so the programmer must take care to keep only currently used data in registers.

The instructions a type of CPU executes make up the CPU’s machine language. Machine programs have a much more basic structure than higher level languages. Machine language instructions are encoded as raw numbers, not in friendly text formats. A CPU must be able to decode an instruction’s purpose very quickly to run efficiently. Machine language is designed with this goal in mind, not to be easily deciphered by humans. Programs written in other languages must be converted to the native machine language of the CPU to run on the computer. A compiler is a program that translates programs written in a programming language into the machine language of a particular computer architecture. In general, every type of CPU has its own unique machine language. This is one reason why programs written for a Mac can not run on an IBM-type PC.

Computers use a clock to synchronize the execution of the instructions.  The clock pulses at a fixed frequency (known as the clock speed). When you buy a 1.5 GHz computer, 1.5 GHz is the frequency of this clock. The clock does not keep track of minutes and seconds. It simply beats at a constant rate. The electronics of the CPU uses the beats to perform their operations correctly, like how the beats of a metronome help one play music at the correct rhythm. The number of beats (or as they are usually called cycles) an instruction requires depends on the CPU generation and model. The number of cycles depends on the instructions before it and other factors as well.

Real Mode

In real mode, memory is limited to only one megabyte (220 bytes). Valid  address range from (in hex) 00000 to FFFFF. These addresses require a 20-bit number. Obviously, a 20-bit number will not fit into any of the 8086’s 16-bit registers. Intel solved this problem, by using two 16-bit values to determine an address. The first 16-bit value is called the selector. Selector values must be stored in segment registers. The second 16-bit value is called the offset. The physical address referenced by a 32-bit selector: offset pair is computed by the formula

Multiplying by 16 in hex is easy, just add a 0 to the right of the number. For example, the physical addresses referenced by 047C:0048 is given by:

In effect, the selector value is a paragraph number (see Table 1.2).

Real segmented addresses have disadvantages:

• A single selector value can only reference 64K of memory (the upper limit of the 16-bit offset). What if a program has more than 64K of code? A single value in CS can not be used for the entire execution of the program. The program must be split up into sections (called segments) less than 64K in size. When execution moves from one segment to another, the value of CS must be changed. Similar problems occur with large amounts of data and the DS register. This can be very awkward!

• Each byte in memory does not have a unique segmented address. The physical address 04808 can be referenced by 047C:0048, 047D:0038, 047E:0028 or 047B:0058. This can complicate the comparison of segmented addresses.

Exercises

4 Supply the   sentences with the missing   words.

access, store, data, unit, frequency

1 Computers … all information in a binary format.

2 The basic … of memory consists of 8 bits and is called a byte.

3 All … in memory is numeric.

4 The CPU can … data in registers much faster than data in memory.

5 The clock pulses at a fixed … (known as the clock speed).

5 Match the concepts  with  their  definitions.

1 Computers

a) is the physical device that performs instructions.

2 A compiler

b) is a program that translates programs written in a programming language into the machine language of a particular computer architecture.

3 The CPU

c) use a clock to synchronize the execution of the instructions.

4 The physical address

d) range from (in hex) 00000 to FFFFF.

5 Valid  address

e) referenced by a 32-bit selector: offset pair is computed by the formula

6 Use the verbs in brackets in the Passive Voice.

1 The table shows how the first few numbers (to represent) in binary.

2 This shows how binary may (to convert) to decimal.

3 Each byte in memory (to label) by a unique number known as its address.

4 Characters (to store) by using a character code that maps numbers of characters.

7 Put the verbs in brackets into a proper tense form.

1 Computers (to use) a clock to synchronize the execution of the instructions.  

2 The clock (not to keep) track of minutes and seconds.

3 Memory in a computer (to consist) of numbers.

4 Each byte in memory (not to have) a unique segmented address.

5 Unicode (to extend) the ASCII values to words and(to allow) many more characters to be represented.

8 Find the Infinitive in the following sentences and define its tense form and function.

1 The ASCII uses one byte to encode a character.

2 Unicode extends the ASCII values to words and allows many more characters to be represented.

3 The programmer must take care to keep only currently used data in registers.

4 Machine language is very difficult to program in directly.

5 Data directives are used in data segments to define room for memory.

Comprehension

9 Ask the following questions on the text and let your group-mates answer them.

1 Does memory in a computer consist of numbers?

2 What is the most significant bit?

3 What base uses hexadecimal numbers?

4 What is the Central Processing Unit?

5 Why do computers use a clock?

10 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

сomputer memory

a binary format

decimal digits

the rightmost decimal digit

a character code

Unicode

valid address range

the native machine language

a fixed frequency

equivalent binary representation

the most common character codes

clock pulses

To supplant

the execution of the instructions

11 Translate into Russian in writing.

«Binary», «Hexadecimal».

12 Translate from Russian into English.

1 В ассемблерных программах регистры используются очень интенсивно.

2 Большинство из них имеет определенное функциональное назначение.

3 Программная модель микропроцессора имеет несколько групп регистров, доступных для использования в программах.

Unit 2

1 Learn the following words and word-combinations.

opcode, n

код операции

deciphering, n

декодирование

tedious, a

утомительный

obvious. a

очевидный

fortunately, adv

к Счастью

mnemonic. n

мнемосхема

porting , n

перенесение

available, a

доступный

implied, p.p.

подразумеваемый

arbitrary,a

произвольный

flexible, a

гибкий

reserved, p.p.

зарезервированный

restriction, n

ограничение

2 Learn the following abbreviations.

NASM  (Netwide Assembler or for short. It is freely available off the Internet);

MASM (Microsoft’s Assembler);

TASM (Borland’s Assembler).

3 Read the texts and be ready to report on the following concepts:

1. «Machine language»;

2. «Assembly language».

Reading

Text 1 Machine language

Every type of CPU understands its own machine language. Instructions in machine language are numbers stored as bytes in memory. Each instruction has its own unique numeric code called its operation code or opcode for short. The 80x86 processor’s instructions vary in size. The opcode is always at the beginning of the instruction. Many instructions also include data (e.g., constants or addresses) used by the instruction.

Machine language is very difficult to program in directly. Deciphering the meanings of the numerical-coded instructions is tedious for humans. For example, the instruction that says to add the EAX and EBX registers together and store the result back into EAX is encoded by the following hex codes:

03 C3

This is hardly obvious. Fortunately, a program called an assembler can do this tedious work for the programmer.

Text 2 Assembly language

An assembly language program is stored as text (just as a higher level language program). Each assembly instruction represents exactly one machine instruction. For example, the addition instruction described above would be represented in assembly language as:

add eax, ebx

Here the meaning of the instruction is much clearer than in machine code. The word add is a mnemonic for the addition instruction. The general form of an assembly instruction is:

mnemonic operand(s)

An assembler is a program that reads a text file with assembly instructions and converts the assembly into machine code. Compilers are programs that do similar conversions for high-level programming languages. An assembler is much simpler than a compiler. Every assembly language statement  directly represents a single machine instruction. High-level language statements are much more complex and may require many machine instructions.

Another important difference between assembly and high-level languages is that since every different type of CPU has its own machine language, it also has its own assembly language. Porting assembly programs between different computer architectures is much more difficult than in a high-level language.

This book’s examples uses the Netwide Assembler or NASM for short. It is freely available off the Internet (see the preface for the URL). More common assemblers are Microsoft’s Assembler (MASM) or Borland’s Assembler (TASM). There are some differences in the assembly syntax for MASM/- TASM and NASM.

Text 3 Instruction operands

Machine code instructions have varying number and type of operands; however, in general, each instruction itself will have a fixed number of operands (0 to 3). Operands can have the following types:

register: These operands refer directly to the contents of the CPU’s registers.

memory: These refer to data in memory. The address of the data may be a constant hardcoded into the instruction or may be computed using values of registers. Address are always offsets from the beginning of a segment.

immediate: These are fixed values that are listed in the instruction itself. They are stored in the instruction itself (in the code segment), not in the data segment.

implied: There operands are not explicitly shown. For example, the increment instruction adds one to a register or memory. The one is implied.

Text 4 Basic instructions

The most basic instruction is the MOV instruction. It moves data from one location to another (like the assignment operator in a high-level language). It takes two operands:

mov dest, src

The data specified by src is copied to dest. One restriction is that both operands may not be memory operands. This points out another quirk of assembly. There are often somewhat arbitrary rules about how the various instructions are used. The operands must also be the same size. The value of AX can not be stored into BL.

Here is an example (semicolons start a comment):

mov eax, 3 ; store 3 into EAX register (3 is immediate operand)

mov bx, ax ; store the value of AX into the BX register

The ADD instruction is used to add integers.

add eax, 4 ; eax = eax + 4

add al, ah ; al = al + ah

The SUB instruction subtracts integers.

sub bx, 10 ; bx = bx - 10

sub ebx, edi ; ebx = ebx - edi

The INC and DEC instructions increment or decrement values by one. Since the one is an implicit operand, the machine code for INC and DEC is smaller than for the equivalent ADD and SUB instructions.

inc ecx ; ecx++

dec dl ; dl--

Text 5 Directives

A directive is an artifact of the assembler not the CPU. They are generally used to either instruct the assembler to do something or inform the assembler of something. They are not translated into machine code. Common uses of directives are:

• define constants

• define memory to store data into

• group memory into segments

• conditionally include source code

• include other files

The equ directive

The equ directive can be used to define a symbol. Symbols are named constants that can be used in the assembly program. The format is:

symbol equ value

Symbol values can not be redefined later.

The %define directive

This directive is similar to C’s #define directive. It is most commonly used to define constant macros just as in C.

%define SIZE 100

mov eax, SIZE

The above code defines a macro named SIZE and shows its use in a MOV instruction. Macros are more flexible than symbols in two ways. Macros can be redefined and can be more than simple constant numbers.

Data directives

Data directives are used in data segments to define room for memory. There are two ways memory can be reserved. The first way only defines room for data; the second way defines room and an initial value. The first method uses one of the RESX directives. The X is replaced with a letter that determines the size of the object (or objects) that will be stored. Table 1.3 shows the possible values.

Exercises

4 Supply the   sentences with the missing   words.

Directives, assembly instructions, machine code, opcode, address, registers.

1 … are generally used to either instruct the assembler to do something or inform the assembler of something.

2 An assembler is a program that reads a text file with … …and converts the assembly into … ….

3 Each instruction has its own unique numeric code called its operation code or … for short.

4 The … of the data may be a constant hardcoded into the instruction or may be computed using values of ….

5 Match the concepts  with  their  definitions.

1 Instructions

a) an artifact of the assembler not the CPU.

2 Compilers

b) named constants that can be used in the assembly program.

3 The word add

c) a mnemonic for the addition instruction.

4 Symbols

d) programs that do conversions for high-level programming languages.

5 A directive

e) numbers stored as bytes in memory.

6 Find Participles in the following sentences and be able to explain their forms.

1 The Central Processing Unit is the physical device performing instructions.

2 Programs written in other languages must be converted to the native machine language of the CPU to run on the computer.

3 Each digit of a hex number has a power of 16 associated with it.

4 Computers use a clock synchronizing the execution of the instructions.

5 The clock pulses at  fixed frequency known as the clock speed.

7 Use the Passive Voice in the following sentences

1 Directives (not to translate ) into machine code.

2 Symbols (to name) constants that can (to use) in the assembly program.

3 There are often somewhat arbitrary rules about how the various instructions (to use).

4 Characters (to store) by using a character code that maps numbers to characters.

5 Base 10 numbers (to compose) of 10 possible digits (0-9).

8 Insert a (an), the or no article where necessary.

1 … directive is … artefact of … assembler not … CPU.

2 …Macros are more flexible than  …symbols in two ways.

3 … Microsoft C++ compiler can use either … OMF format or … Win32 format.

4 …C code requires … Standard C library and … special startup code to run.

Comprehension

9 Ask the following questions on the text and let your group-mates answer them.

1 Does every type of CPU understand its own machine language?

2 Each assembly instruction represents exactly one machine instruction, doesn’t it?

3 What is the assembler?

4 Do machine code instructions have varying number and type of operands?

5 Operands can have  several types. What are they?

6 What instruction is the most basic?

7 What is used in data segments to define room for memory?

10 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

own unique numeric code

Deciphering

a text file

high-level programming languages

high-level language statements

assembly language statement  

machine code instructions

an assembly language program

data directives

operation code

an initial value

increment or decrement values by one

11 Translate into Russian in writing.

Text 5 «Directives», «The equ directive», «The %define directive», «Data directives».

12 Translate from Russian into English.

1 Заголовочные файлы подключаются к компилируемому файлу исходного кода с помощью директивы препроцессора #include, за которой следует имя заголовочного файла в кавычках или угловых скобках.
2 Свойству можно присваивать значение, извлекать из него значение и вообще вроде бы делать с ним все то, что делают с простым полем.

Unit 3

1 Learn the following words and word-combinations.

define, v

определять

store, v

хранить, запоминать

terminate, v

прекращать. прерывать

convention, n

соглашение

directive, n

директива

startup code

начальный код

2 Learn the following abbreviations.

COFF (Common Object File Format) – общий формат файлов объектов;

ELF (Executable and Linkable Format) – формат выполняемых и связанных файлов.

3 Read the texts and be ready to report on the following concepts:

1. «Creating a program»;

2. «Compiler dependencies».

Text 1  Creating a Program

Today, it is unusual to create a stand alone program written completely in assembly language. Assembly is usually used to key certain critical routines. Why? It is much easier to program in a higher level language than in assembly. Also, using assembly makes a program very hard to port to other platforms. In fact, it is rare to use assembly at all.

So, why should anyone learn assembly at all?

1. Sometimes code written in assembly can be faster and smaller than compiler generated code.

2. Assembly allows access to direct hardware features of the system that might be difficult or impossible to use from a higher level language.

3. Learning to program in assembly helps one gain a deeper understanding of how computers work.

4. Learning to program in assembly helps one understand better how compilers and high level languages like C work.

These last two points demonstrate that learning assembly can be useful even if one never programs in it later. In fact, the author rarely programs in assembly, but he uses the ideas he learned from it everyday.

Text 2 First program

The early programs in this text will all start from the simple C driver program in Figure 1.6. It simply calls another function named asm main. This is really a routine that will be written in assembly. There are several advantages in using the C driver routine. First, this lets the C system set up the program to run correctly in protected mode. All the segments and their corresponding segment registers will be initialized by C. The assembly code need not worry about any of this. Secondly, the C library will also be available to be used by the assembly code. The author’s I/O routines take advantage of this. They use C’s I/O functions (printf, etc.). The following shows a simple assembly program.

first.asm

1 ; file: first.asm

2 ; First assembly program. This program asks for two integers as

3 ; input and prints out their sum.

4 ;

5 ; To create executable using djgpp:

6 ; nasm -f coff first.asm

7 ; gcc -o first first.o driver.c asm_io.o

8

9 %include "asm_io.inc"

10 ;

11 ; initialized data is put in the .data segment

12 ;

13 segment .data

14 ;

15 ; These labels refer to strings used for output

16 ;

17 prompt1 db "Enter a number: ", 0 ; don’t forget null terminator

18 prompt2 db "Enter another number: ", 0

19 outmsg1 db "You entered ", 0

20 outmsg2 db " and ", 0

21 outmsg3 db ", the sum of these is ", 0

22

23 ;

24 ; uninitialized data is put in the .bss segment

25 ;

26 segment .bss

27 ;

28 ; These labels refer to double words used to store the inputs

29 ;

30 input1 resd 1

31 input2 resd 1

32

33 ;

34 ; code is put in the .text segment

35 ;

36 segment .text

37 global _asm_main

38 _asm_main:

39 enter 0,0 ; setup routine

40 pusha

41

42 mov eax, prompt1 ; print out prompt

43 call print_string

44

45 call read_int ; read integer

46 mov [input1], eax ; store into input1

47

48 mov eax, prompt2 ; print out prompt

49 call print_string

50

51 call read_int ; read integer

52 mov [input2], eax ; store into input2

53

54 mov eax, [input1] ; eax = dword at input1

55 add eax, [input2] ; eax += dword at input2

56 mov ebx, eax ; ebx = eax

57

58 dump_regs 1 ; print out register values

59 dump_mem 2, outmsg1, 1 ; print out memory

60 ;

61 ; next print out result message as series of steps

62 ;

63 mov eax, outmsg1

64 call print_string ; print out first message

65 mov eax, [input1]

66 call print_int ; print out input1

67 mov eax, outmsg2

68 call print_string ; print out second message

69 mov eax, [input2]

70 call print_int ; print out input2

71 mov eax, outmsg3

1.4. CREATING A PROGRAM 21

72 call print_string ; print out third message

73 mov eax, ebx

74 call print_int ; print out sum (ebx)

75 call print_nl ; print new-line

76

77 popa

78 mov eax, 0 ; return back to C

79 leave

80 ret first.asm

Line 13 of the program defines a section of the program that specifies memory to be stored in the data segment (whose name is .data). Only initialized data should be defined in this segment. On lines 17 to 21, several strings are declared. They will be printed with the C library and so must be terminated with a null character (ASCII code 0). Remember there is a big difference between 0 and ’0’.

Uninitialized data should be declared in the bss segment (named .bss on line 26). This segment gets its name from an early UNIX-based assembler operator that meant “block started by symbol.” There is also a stack segment too. It will be discussed later.

The code segment is named .text historically. It is where instructions are placed. Note that the code label for the main routine (line 38) has an underscore prefix. This is part of the C calling convention. This convention specifies the rules C uses when compiling code. It is very important to know this convention when interfacing C and assembly. Later the entire convention will be presented; however, for now, one only needs to know that all C symbols (i.e., functions and global variables) have a underscore prefix appended to them by the C compiler. (This rule is specifically for DOS/Windows, the Linux C compiler does not prepend anything to C symbol names.)

The global directive on line 37 tells the assembler to make the asm main label global. Unlike in C, labels have internal scope by default. This means that only code in the same module can use the label. The global directive gives the specified label (or labels) external scope. This type of label can be accessed by any module in the program. The asm io module declares the print int, et.al. labels to be global. This is why one can use them in the first.asm module.

Text 3 Compiler dependencies

The assembly code above is specific to the free GNU9-based DJGPP C/C++ compiler.10 This compiler can be freely downloaded from the Internet. It requires a 386-based PC or better and runs under DOS, Windows 95/98 or NT. This compiler uses object files in the COFF (Common Object File Format) format. To assemble to this format use the -f coff switch with nasm (as shown in the comments of the above code). The extension of the resulting object file will be o.

The Linux C compiler is a GNU compiler also. To convert the code above to run under Linux, simply remove the underscore prefixes in lines 37 and 38. Linux uses the ELF (Executable and Linkable Format) format for object files. Use the -f elf switch for Linux. It also produces an object with an o extension.

Borland C/C++ is another popular compiler. It uses the Microsoft OMF format for object files. Use the -f obj switch for Borland compilers. The extension of the object file will be obj. The OMF format uses different segment directives than the other object formats. The data segment (line 13) must be changed to:

segment DATA public align=4 class=DATA use32

The bss segment (line 26) must be changed to:

segment BSS public align=4 class=BSS use32

The text segment (line 36) must be changed to:

segment TEXT public align=1 class=CODE use32

In addition a new line should be added before line 36:

group DGROUP BSS DATA

The Microsoft C/C++ compiler can use either the OMF format or the Win32 format for object files. (If given a OMF format, it converts the information to Win32 format internally.) Win32 format allows segments to be defined just as for DJGPP and Linux. Use the -f win32 switch to output in this mode. The extension of the object file will be obj.

Text 4 Assembling the code

The first step is to assembly the code. From the command line, type:

nasm -f object-format first.asm

where object-format is either coff , elf , obj or win32 depending on what C compiler will be used. (Remember that the source file must be changed for both Linux and Borland as well.)

When compiling the C code, compile the driver.c file using a C compiler. For DJGPP, use:

gcc -c driver.c

The -c switch means to just compile, do not attempt to link yet. This same switch works on Linux, Borland and Microsoft compilers as well.

Text 5 Linking the object files

Linking is the process of combining the machine code and data in object files and library files together to create an executable file. As will be shown below, this process is complicated.

C code requires the standard C library and special start up code to run. It is much easiler to let the C compiler call the linker with the correct parameters, than to try to call the linker directly. For example, to link the code for the first program using DJGPP, use:

gcc -o first driver.o first.o asm io.o

This creates an executable called first.exe (or just first under Linux).

With Borland, one would use:

bcc32 first.obj driver.obj asm io.obj

Borland uses the name of the first file listed to determine the executable name. So in the above case, the program would be named first.exe.

It is possible to combine the compiling and linking step. For example,

gcc -o first driver.c first.o asm io.o

Now gcc will compile driver.c and then link.

4 Supply the sentences with the missing words.

Assembly, code segment, segment registers, conventions

1 … is  usually used to key certain critical rouines.

2 All the segments and their corresponding … … will be initialized by C.

3 The … … is named .text historically.

4 It is very important to know all … when interfacing C and assembly.

5 Match the concepts with their definitions.

1 Assembly

a) is the process of combining the machine ode and data in object files and library files together to create an executable file.

2 Linking

b) is usually used to key certain critical routines.

3 Obj

c) requires the standard C library and special start up code to run.

4 C code

d) is extension of the object file.

6 Fill in a, the or no article.

1 Note that … code label for … main routine (line 38) has …underscore prefix.  

2 Linking is … process of combining …machine code and data in … object files and …library files together to create … executable file.

3 …extension of … object file will be obj.

4 Learning to program in …assembly helps one understand better how … compilers and …high level languages like C work.

5 … opcode is always at … beginning of … instruction.

7 Say the following sentences using Indirect speech.

1 The teacher said, “Today, it is unusual to create a stand alone program written completely in assembly language”.

2 What compilers have you read about in text 3?- asked my group-mate.

3 The developer said, “Borland C/C++ compiler uses the Microsoft OMF format for object files”.

4 “Is the most common character code known as ASCII (American Standard Code for Information Interchange?- asked the teacher.

Comprehension

8 Ask the following questions on the text and let your group-mates answer them.

1 What is Assembly used for?

2 Why should anyone learn assembly?

3 Does assembly allow access to direct hardware features of the system?

4 What are several advantages in using the C driver routine?

5 What is the extension of the object file?

9 Find Russian equivalents for the following words and word-combinations and then put them down in  the right column.

a stand alone program

routines

compiler generated code

a higher level language

advantages

the assembly code

data segment

data segment

the C driver routine

a simple C driver program

take advantage

a global directive

10 Translate into Russian in writing.

«Creating a Program», «First Program».

11 Translate from Russian into English.

1 Ассемблер позволяет писать наиболее быстрые приложения доступа к аппаратным средствам.

2 Инициализация данных должна заканчиваться нулевым символом.

3 В отличие от языка С, переменные Ассемблера являются по умолчанию локальными.

Unit 4

1 Learn the following words and word-combinations.

complicate, (v)

затруднять, осложнять, усложнять;

consider, (v)

рассматривать, обсуждать;

decrease, (n)

уменьшение, убывание, убавление, сокращение;

drawback,(n)

недостаток, отрицательная сторона;

hex, (n)

(hexadecimal) шестнадцатеричная система счисления, шестнадцатеричное число;

integer representation  

целочисленное представление;

increase, (n)

расширение, увеличение;

one's complement , (n)

(поразрядное) дополнение до единицы; обратный код (числа) ( в двоичной системе );

recast, (v)

рассматривать;

represent, (v)

быть изображением, представлять;

reverse, (a)

перевернутый, обратный, оборотный, инвертированный;

sign extension, (n)

расширение знака;

signed magnitude, (n)

величина со знаком;

signed integer, (n)

целое число со знаком;

unsigned integer, (n)

целое число без знака;

significant, (a)

значимый, значащий;

straightforward binary,

прямой код, прямое представление двоичного числа;

subtract, (v)

вычитать;

two’s complement, (n)

двойное дополнение;

yield, (v)

получать, давать (в результате какой-либо операции);

2 Read the texts bellow  and explain the followings points.

  1.  How to represent signed integers in binary form using signed magnitude method?
  2.  How to represent signed integer in binary form using two’s complement method?

Reading

Text 1 Working with Integers

Integers come in two flavours: unsigned and signed. Unsigned integers (which are non-negative) are represented in a very straightforward binary manner. The number 200 as an one byte unsigned integer would be represented as by 11001000 (or C8 in hex).

Signed integers (which may be positive or negative) are represented in a more complicated ways. For example, consider −56. +56 as a byte would be represented by 00111000. On paper, one could represent −56 as −111000, but how would this be represented in a byte in the computer’s memory. How would the minus sign be stored?

There are three general techniques that have been used to represent signed integers in computer memory. All of these methods use the most significant bit of the integer as a sign bit. This bit is 0 if the number is positive and 1 if negative.

Text 2 Signed magnitude

The first method is the simplest and is called signed magnitude. It represents the integer as two parts. The first part is the sign bit and the second is the magnitude of the integer. So 56 would be represented as the byte 00111000 (the sign bit is underlined) and −56 would be 10111000. The largest byte value would be 01111111 or +127 and the smallest byte value would be 11111111 or −127. To negate a value, the sign bit is reversed. This method is straightforward, but it does have its drawbacks. First, there are two possible values of zero, +0 (00000000) and −0 (10000000). Since zero is neither positive nor negative, both of these representations should act the same. This complicates the logic of arithmetic for the CPU. Secondly, general arithmetic is also complicated. If 10 is added to −56, this must be recast as 10 subtracted by 56. Again, this complicates the logic of the CPU.

Text 3 One’s complement

The second method is known as one’s complement representation. The one’s complement of a number is found by reversing each bit in the number. (Another way to look at it is that the new bit value is 1−oldbitvalue.) For example, the one’s complement of 00111000 (+56) is 11000111. In one’s complement notation, computing the one’s complement is equivalent to negation. Thus, 11000111 is the representation for −56. Note that the sign bit was automatically changed by one’s complement and that as one would expect taking the one’s complement twice yields the original number. As for the first method, there are two representations of zero: 00000000 (+0) and 11111111 (−0). Arithmetic with one’s complement numbers is complicated.

There is a handy trick to finding the one’s complement of a number in hexadecimal without converting it to binary. The trick is to subtract the hex digit from F (or 15 in decimal). This method assumes that the number of bits in the number is a multiple of 4. Here is an example: +56 is represented by 38 in hex. To find the one’s complement, subtract each digit from F to get C7 in hex. This agrees with the result above.

Text 4 Two’s complement

The first two methods described were used on early computers. Modern computers use a third method called two’s complement representation. The two’s complement of a number is found by the following two steps:

1. Find the one’s complement of the number

2. Add one to the result of step 1

Here’s an example using 00111000 (56). First the one’s complement is computed: 11000111. Then one is added:

In two complement’s notation, computing the two’s complement is equivalent to negating a number. Thus, 11001000 is the two’s complement representation of −56. Two negations should reproduce the original number. Surprising two’s complement does meet this requirement. Take the two’s complement of 11001000 by adding one to the one’s complement.

When performing the addition in the two’s complement operation, the addition of the leftmost bit may produce a carry. This carry is not used. Remember that all data on the computer is of some fixed size (in terms of number of bits). Adding two bytes always produces a byte as a result (just as adding two words produces a word, etc.) This property is important for two’s complement notation. For example, consider zero as a one byte two’s complement number (00000000). Computing its two complement produces the sum:

where c represents a carry. (Later it will be shown how to detect this carry, but it is not stored in the result.) Thus, in two’s complement notation there is only one zero. This makes two’s complement arithmetic simpler that the previous methods.

Using two’s complement notation, a signed byte can be used to represent the numbers −128 to +127. Table 2.1 shows some selected values. If 16 bits are used, the signed numbers −32, 768 to +32, 767 can be represented. +32, 767 is represented by 7FFF, −32, 768 by 8000, -128 as FF80 and -1 as FFFF. 32 bit two’s complement numbers range from −2 billion to +2 billion approximately.

The CPU has no idea what a particular byte (or word or double word) is supposed to represent. Assembly does not have the idea of types that a high level language has. How data is interpreted depends on what instruction is used on the data. Whether the hex value FF is considered to represent a signed −1 or a unsigned +255 depends on the programmer. The C language defines signed and unsigned integer types. This allows a C compiler to determine the correct instructions to use with the data.

Text 5 Sign extension

In assembly, all data has a specified size. It is not uncommon to need to change the size of data to use it with other data. Decreasing size is the easiest.

Decreasing size of data

To decrease the size of data, simply remove the more significant bits of the data. Here’s a trivial example:

mov ax, 0034h ; ax = 52 (stored in 16 bits)

mov cl, al ; cl = lower 8-bits of ax

Of course, if the number can not be represented correctly in the smaller size, decreasing the size does not work. For example, if AX were 0134h (or 308 in decimal) then the above code would still set CL to 34h. This method works with both signed and unsigned numbers. Consider signed numbers, if AX was FFFFh (−1 as a word), then CL would be FFh (−1 as a byte). However, note that this is not correct if the value in AX was unsigned!

The rule for unsigned numbers is that all the bits being removed must be 0 for the conversion to be correct. The rule for signed numbers is that the bits being removed must be either all 1’s or all 0’s. In addition, the first bit not being removed must have the same value as the removed bits. This bit will be the new sign bit of the smaller value. It is important that it be same as the original sign bit!

Increasing size of data

Increasing the size of data is more complicated than decreasing. Consider the hex byte FF. If it is extended to a word, what value should the word have? It depends on how FF is interpreted. If FF is a unsigned byte (255 in decimal), then the word should be 00FF; however, if it is a signed byte (−1 in decimal), then the word should be FFFF.

In general, to extend an unsigned number, one makes all the new bits of the expanded number 0. Thus, FF becomes 00FF. However, to extend a signed number, one must extend the sign bit. This means that the new bits become copies of the sign bit. Since the sign bit of FF is 1, the new bits must also be all ones, to produce FFFF. If the signed number 5A (90 in decimal) was extended, the result would be 005A.

There are several instructions that the 80386 provides for extension of numbers. Remember that the computer does not know whether a number is signed or unsigned. It is up to the programmer to use the correct instruction.

For unsigned numbers, one can simply put zeros in the upper bits using a MOV instruction. For example, to extend the byte in AL to an unsigned word in AX:

mov ah, 0 ; zero out upper 8-bits

However, it is not possible to use a MOV instruction to convert the unsigned word in AX to an unsigned double word in EAX. Why not? There is no way to specify the upper 16 bits of EAX in a MOV. The 80386 solves this problem by providing a new instruction MOVZX. This instruction has two operands. The destination (first operand) must be a 16 or 32 bit register. The source (second operand) may be an 8 or 16 bit register or a byte or word of memory. The other restriction is that the destination must be larger than than the source. (Most instructions require the source and destination to be the same size.) Here are some examples:

movzx eax, ax ; extends ax into eax

movzx eax, al ; extends al into eax

movzx ax, al ; extends al into ax

movzx ebx, ax ; extends ax into ebx

For signed numbers, there is no easy way to use the MOV instruction for any case. The 8086 provided several instructions to extend signed numbers. The CBW (Convert Byte to Word) instruction sign extends the AL register into AX. The operands are implicit. The CWD (Convert Word to Double word) instruction sign extends AX into DX:AX. The notation DX:AX means to think of the DX and AX registers as one 32 bit register with the upper 16 bits in DX and the lower bits in AX. (Remember that the 8086 did not have any 32 bit registers!) The 80386 added several new instructions. The CWDE (Convert Word to Double word Extended) instruction sign extends AX into EAX. The CDQ (Convert Double word to Quad word) instruction sign extends EAX into EDX:EAX (64 bits!). Finally, the MOVSX instruction works like MOVZX except it uses the rules for signed numbers.

3 Find the correct ending in the right column.

1 Signed integers

a) represents the integer as two parts;

2 Unsigned integers

b) is found by reversing each bit in the number;

3 Signed magnitude

c) may be positive or negative. They are represented  by three general techniques

negative;

4 One’s complement

d) are represented in a very straightforward binary manner;

4 Supply the sentences with the missing words.

Increasing, signed magnitude, signed integers, two’s complement.

1) The first method is the simplest and is called .... .

2) Modern computers use a third method called ... ... representation.

3) ... the size of data is more complicated than decreasing.

4)... are represented in a more complicated ways.

5 Insert a(an), the or no article where it is necessary.

1 It is much easier to program in … higher level language than in assembly.

2 …first step is to assembly … code.

3 Borland uses … name of … first file listed to determine … executable name.

4 Unlike in C, - labels have -internal scope by - default.

5 - code label for - main routine (line 38) has - underscore prefix.

6 Use the following sentences in the Passive voice.

1 Signed integers (which may be positive or negative) (to represent) in a more complicated ways.

2 This is really a routine that will  (to write) in assembly.

3 Only initialized data should (to define) in this segment

4 An AND operation (to perform) with the TEST instruction.

5 This type of label can (to access) by any module in the program.

Comprehension

7 Answer the following questions.

1 What methods were used on early computers?

2 How many general techniques have been used to represent signed integers in computer memory?

3 What steps should you perform to find two’s complement of a number?

4 What programming language defines signed and unsigned integer types?

5 Do all data in assembly have a specified size?

6 What is the easiest – decreasing or increasing memory size?

7 Does computer know whether a number is signed or unsigned?

8 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

the more significant bit

two’s complement representation

original sign bit

two complement’s notation

straightforward binary

an unsigned number

the leftmost bit

a signed magnitude

a signed number

sign extension

two’s complement operation

general arithmetic

9 Translate into Russian in writing.

Text 2 «Signed magnitude», Text 5 «Decreasing size of data».

10 Translate into English.

1 Найти обратный код шестнадцатиричного числа без перехода к двоичному представлению является сложной операцией.

2 Операция уменьшения размера данных работает некорректно, если размер данных превышает отведенное место.

3 Есть два вида целых чисел: знаковые и без знаковые.

Unit 5

1 Learn the following words and word-combinations.

assemble, v

собирать, компоновать, транслировать программу

branch, n

ветвь(исп. в условных операторах)

condition, n

условие, состояние, ситуация

compute, v

вычислять, рассчитывать

default type

тип по-умолчанию

implementation, n

внедрение, ввод в работу, реализация.

instruction, n

Команда, инструкция, программа действий.

keyword, n

ключевое слово

label, n

Метка

linker, n

компоновщик.

loop, n

цикл, петля

odd. a

нечетный, добавочный.

overflow, n

переполнение, избыток

sign flag

флаг знака (+ или -)

statement. n

выражение

unsigned integer

беззнаковое целое число

2 Read the texts bellow and report on the following concepts:

1. «Translating Standard Control Structures»;

2. «Branch instructions: SHORT jump»;

3. «Branch instructions: NEAR jump».

Reading

Text 1 Control Structures

High level languages provide high level control structures (e.g., the if and while statements) that control the thread of execution. Assembly language does not provide such complex control structures. It instead uses the infamous goto and used inappropriately can result in spaghetti code! However, it is possible to write structured assembly language programs. The basic procedure is to design the program logic using the familiar high level control structures and translate the design into the appropriate assembly language (much like a compiler would do).

Text 2 Comparisons

Control structures decide what to do based on comparisons of data. In assembly, the result of a comparison is stored in the FLAGS register to be used later. The 80x86 provides the CMP instruction to perform comparisons. The FLAGS register is set based on the difference of the two operands of the CMP instruction. The operands are subtracted and the FLAGS are set based on the result, but the result is not stored anywhere. If you need the result use the SUB instead of the CMP instruction.For unsigned integers, there are two flags (bits in the FLAGS register) that are important: the zero (ZF) and carry (CF) flags. The zero flag is set (1) if the resulting difference would be zero. The carry flag is used as a borrow flag for subtraction. Consider a comparison like:

cmp vleft, vright

The difference of vleft - vright is computed and the flags are set accordingly. If the difference of the of CMP is zero, vleft = vright, then ZF is set (i.e. 1) and the CF is unset (i.e. 0). If vleft > vright, then ZF is unset and CF is unset (no borrow). If vleft < vright, then ZF is unset and CF is set (borrow).

For signed integers, there are three flags that are important: the zero (ZF) flag, the overflow (OF) flag and the sign (SF) flag. The overflow flag  is set if the result of an operation overflows (or underflows). The sign flag is set if the result of an operation is negative. If vleft = vright, the ZF is set (just as for unsigned integers). If vleft > vright, ZF is unset and SF = OF. If vleft < vright, ZF is unset and SF 6= OF.

Do not forget that other instructions can also change the FLAGS register, not just CMP.

Text 3 Branch instructions

Branch instructions can transfer execution to arbitrary points of a program. In other words, they act like a goto. There are two types of branches: unconditional and conditional. An unconditional branch is just like a goto, it always makes the branch. A conditional branch may or may not make the branch depending on the flags in the FLAGS register. If a conditional branch does not make the branch, control passes to the next instruction.

The JMP (short for jump) instruction makes unconditional branches. Its single argument is usually a code label to the instruction to branch to. The assembler or linker will replace the label with correct address of the instruction. This is another one of the tedious operations that the assembler does to make the programmer’s life easier. It is important to realize that the statement immediately after the JMP instruction will never be executed unless another instruction branches to it!

There are several variations of the jump instruction:

SHORT This jump is very limited in range. It can only move up or down 128 bytes in memory. The advantage of this type is that it uses less memory than the others. It uses a single signed byte to store the displacement of the jump. The displacement is how many bytes to move ahead or behind. (The displacement is added to EIP). To specify a short jump, use the SHORT keyword immediately before the label in the JMP instruction.

NEAR This jump is the default type for both unconditional and conditional branches, it can be used to jump to any location in a segment. Actually, the 80386 supports two types of near jumps. One uses two bytes for the displacement. This allows one to move up or down roughly 32,000 bytes. The other type uses four bytes for the displacement, which of course allows one to move to any location in the code segment. The four byte type is the default in 386 protected mode. The two byte type can be specified by putting the WORD keyword before the label in the JMP instruction.

FAR This jump allows control to move to another code segment. This is a very rare thing to do in 386 protected mode.

Valid code labels follow the same rules as data labels. Code labels are defined by placing them in the code segment in front of the statement they label. A colon is placed at the end of the label at its point of definition. The colon is not part of the name.

There are many different conditional branch instructions. They also take a code label as their single operand. The simplest ones just look at a single flag in the FLAGS register to determine whether to branch or not. See Table 2.3 for a list of these instructions. (PF is the parity flag which indicates the odd or evenness of the number of bits set in the lower 8-bits of the result.)

The following pseudo-code:

if ( EAX == 0 )

EBX = 1;

else

EBX = 2;

could be written in assembly as:

1 cmp eax, 0 ; set flags (ZF set if eax - 0 = 0)

2 jz thenblock ; if ZF is set branch to thenblock

3 mov ebx, 2 ; ELSE part of IF

4 jmp next ; jump over THEN part of IF

5 thenblock:

6 mov ebx, 1 ; THEN part of IF

7 next:

Other comparisons are not so easy using the conditional branches in Table 2.3. To illustrate, consider the following pseudo-code:

if ( EAX >= 5 )

EBX = 1;

else

EBX = 2;

If EAX is greater than or equal to five, the ZF may be set or unset and SF will equal OF. Here is assembly code that tests for these conditions (assuming that EAX is signed):

1 cmp eax, 5

2 js signon ; goto signon if SF = 1

3 jo elseblock ; goto elseblock if OF = 1 and SF = 0

4 jmp thenblock ; goto thenblock if SF = 0 and OF = 0

5 signon:

6 jo thenblock ; goto thenblock if SF = 1 and OF = 1

7 elseblock:

8 mov ebx, 2

9 jmp next

10 thenblock:

11 mov ebx, 1

12 next:

The above code is very awkward. Fortunately, the 80x86 provides additional branch instructions to make these type of tests much easier. There are signed and unsigned versions of each. Table 2.4 shows these instructions.The equal and not equal branches (JE and JNE) are the same for both signed and unsigned integers. (In fact, JE and JNE are really identical to JZ and JNZ, respectively.) Each of the other branch instructions have two synonyms. For example, look at JL (jump less than) and JNGE (jump not greater than or equal to). These are the same instruction because:

x < y =) not(x _ y)

The unsigned branches use A for above and B for below instead of L and G. Using these new branch instructions, the pseudo-code above can be translated to assembly much easier.

1 cmp eax, 5

2 jge thenblock

3 mov ebx, 2

4 jmp next

5 thenblock:

6 mov ebx, 1

7 next:

Text 4 The loop instructions

The 80x86 provides several instructions designed to implement for –like loops. Each of these instructions takes a code label as its single operand.

LOOP Decrements ECX, if ECX 6= 0, branches to label

LOOPE, LOOPZ Decrements ECX (FLAGS register is not modified), if ECX 6= 0 and ZF = 1, branches

LOOPNE, LOOPNZ Decrements ECX (FLAGS unchanged), if ECX 6= 0 and ZF = 0, branches

The last two loop instructions are useful for sequential search loops. The following pseudo-code:

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

3 loop_start:

4 add eax, ecx

5 loop loop_start

Text 5 Translating Standard Control Structures

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

1 If 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

5 else_block:

6 ; code for else block

7 endif:

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

branch to endif.

1 ; code to set FLAGS

2 jxx endif ; select xx so that branches if condition false

3 ; code for then block

4 endif:

2.3.2 While loops

The while loop is a top tested loop:

while( condition ) {

body of loop;

}

This could be translated into:

1 while:

2 ; code to set FLAGS based on condition

3 jxx endwhile ; select xx so that branches if false

4 ; body of loop

5 jmp while

6 endwhile:

2 Do while loops

The do while loop is a bottom tested loop:

do {

body of loop;

} while( condition );

This could be translated into:

1 do:

2 ; body of loop

3 ; code to set FLAGS based on condition

4 jxx do ; select xx so that branches if true

Text 6 Finding Prime Numbers

This section looks at a program that finds prime numbers. Recall that prime numbers are evenly divisible by only 1 and themselves. There is no formula for doing this. The basic method this program uses is to find the factors of all odd numbers3 below a given limit. If no factor can be found for an odd number, it is prime. Figure 2.3 shows the basic algorithm written in C.

Here’s the assembly version:

 

prime.asm

1 %include "asm_io.inc"

2 segment .data

3 Message db "Find primes up to: ", 0

4

5 segment .bss

6 Limit resd 1 ; find primes up to this limit

7 Guess resd 1 ; the current guess for prime

8

9 segment .text

10 global _asm_main

11 _asm_main:

12 enter 0,0 ; setup routine

13 pusha

14

15 mov eax, Message

16 call print_string

17 call read_int ; scanf("%u", & limit );

18 mov [Limit], eax

20 mov eax, 2 ; printf("2\n");

21 call print_int

22 call print_nl

23 mov eax, 3 ; printf("3\n");

24 call print_int

25 call print_nl

26

27 mov dword [Guess], 5 ; Guess = 5;

28 while_limit: ; while ( Guess <= Limit )

29 mov eax,[Guess]

30 cmp eax, [Limit]

31 jnbe end_while_limit ; use jnbe since numbers are unsigned

32

33 mov ebx, 3 ; ebx is factor = 3;

34 while_factor:

35 mov eax,ebx

36 mul eax ; edx:eax = eax*eax

37 jo end_while_factor ; if answer won’t fit in eax alone

38 cmp eax, [Guess]

39 jnb end_while_factor ; if !(factor*factor < guess)

40 mov eax,[Guess]

41 mov edx,0

42 div ebx ; edx = edx:eax % ebx

43 cmp edx, 0

44 je end_while_factor ; if !(guess % factor != 0)

45

46 add ebx,2 ; factor += 2;

47 jmp while_factor

48 end_while_factor:

49 je end_if ; if !(guess % factor != 0)

50 mov eax,[Guess] ; printf("%u\n")

51 call print_int

52 call print_nl

53 end_if:

54 add dword [Guess], 2 ; guess += 2

55 jmp while_limit

56 end_while_limit:

58 popa

59 mov eax, 0 ; return back to C

60 leave

61 ret prime.asm

3  Supply the sentences with the missing words.

Two byte type, branch instructions, code labels, control structures ,the statement, keyword.

1 The … …  ...  can be specified by putting the WORD  ...  before the label in the JMP instruction.

2 …  ...    are defined by placing them in the code segment in front of the statement they label.

3 The basic procedure is to design the program logic using the familiar high level   ...  … and

translate the design into the appropriate assembly language.

4  …   ...   can transfer execution to arbitrary points of a program.

5 It is important to realize that   ...   immediately after the JMP instruction will never be executed unless another instruction branches to it!

4 Find the correct ending in the right column.

1 Assembler

a)are defined by placing them in the code segment in front of the statement they label.

2 SHORT jump

  1.  b)is a language that does not provide complex control structures, but it uses the goto instead.

3 Code labels

  1.  c) is used as a borrow flag for subtraction.

4 Carry flag

  1.  d)Is a very limited in range type of  jump. It can only move up or down 128 bytes in memory

5 Insert a (an), the or no article where it is necessary.

  1.  1 For signed integers, there are three flags that are important: … zero (ZF) flag, … overflow (OF) flag and … sign (SF) flag.

2  above code is very awkward.

3 operands are subtracted and … FLAGS are set based on … result

4 … other type uses four bytes for … displacement, which of course allows one to move to any location in … code segment.

6 Put the verbs in brackets into a proper tense form.

1 The MOVSX instruction  (to work) like MOVZX except it (to use) the rules for signed numbers.

2 Remember that the computer (not to know) whether a number is signed or unsigned.

3 This section (to look) at a program that (to find) prime numbers.

4 Assembly (not to have) the idea of types that a high level language (to have).

5 Deciphering the meanings of the numerical-coded instructions(to be) tedious for humans.

Comprehension

7 Answer the following questions.

  1.  What is the basic procedure when trying to write structured assembly language programs?
  2.  What two flags are important for unsigned integers?
  3.  What three flags are important for signed integers?
  4.  What kind of variations of the jump instruction do you know?
  5.  What is the difference between equal and non equal branches?
  6.  Which jump type allows you control to move to another code segment?
  7.  How many synonyms do branch instructions have?

8 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

high level control structures

structured assembly language programs

the program logic

the overflow flag

the sign flag

an  unconditional branch

a conditional branch

the displacement of the jump

the code segment

valid code labels

a colon

branch instructions

standard control structures

prime numbers

9 Translate into Russian in writing.

Text 2 «Comparisons», Text 3 «Branch instructions».

  1.  

10 Translate into English.

1 Ассемблер – низкоуровневый язык программирования, не поддерживающий структурированных условных операторов.

2 Используя условные операторы, вы можете мгновенно переместиться в любую точку программы.

3 Чтобы программировать на языке ассемблер, вам недостаточно быть просто программистом. Вы также должны хорошо разбираться в аппаратном обеспечении, для которого вы пишите программу.

Unit 6

1 Learn the following words and word-combinations.

assembly language

язык ассемблера

shift instructions

инструкции сдвига

rotate shift

обратный сдвиг

significant, a

значимый, значительный

arithmetic shift

арифметический сдвиг

instruction, n

инструкция, команда

register, n

регистр

multiplication, n

умножение

code snippet

фрагмент кода

2 Learn the following abbreviations.

SAL (Shift Arithmetic Left) – арифметический сдвиг влево;

SAR (Shift Arithmetic Right) – арифметический сдвиг вправо;

SHL (Shift Left) – сдвиг влево;

SHR (Shift Right) – сдвиг вправо.

3 Read the texts bellow and report on the following concepts:

1. «Arithmetic shifts»;

2. «Rotate shifts».

Reading

Text 1 Shift Operations

Assembly language allows the programmer to manipulate the individual bits of data. One common bit operation is called a shift. A shift operation moves the position of the bits of some data. Shifts can be either toward the left (i.e. toward the most significant bits) or toward the right (the least significant bits).

Logical shifts

A logical shift is the simplest type of shift. It shifts in a very straightforward manner. Figure 3.1 shows an example of a shifted single byte number.

Note that new, incoming bits are always zero. The SHL and SHR instructions are used to perform logical left and right shifts respectively. These instructions allow one to shift by any number of positions. The number of positions to shift can either be a constant or can be stored in the CL register. The last bit shifted out of the data is stored in the carry flag. Here are some code examples:

1 mov ax, 0C123H

2 shl ax, 1 ; shift 1 bit to left, ax = 8246H, CF = 1

3 shr ax, 1 ; shift 1 bit to right, ax = 4123H, CF = 0

4 shr ax, 1 ; shift 1 bit to right, ax = 2091H, CF = 1

5 mov ax, 0C123H

6 shl ax, 2 ; shift 2 bits to left, ax = 048CH, CF = 1

7 mov cl, 3

8 shr ax, cl ; shift 3 bits to right, ax = 0091H, CF = 1

Text 2 Use of shifts

Fast multiplication and division are the most common uses of a shift operations. Recall that in the decimal system, multiplication and division by a power of ten are simple, just shift digits. The same is true for powers of two in binary. For example, to double the binary number 10112 (or 11 in decimal), shift once to the left to get 101102 (or 22). The quotient of a division by a power of two is the result of a right shift. To divide by just 2, use a single right shift; to divide by 4 (22), shift right 2 places; to divide by 8 (23), shift 3 places to the right, etc. Shift instructions are very basic and are much faster than the corresponding MUL and DIV instructions!

Actually, logical shifts can be used to multiply and divide unsigned values. They do not work in general for signed values. Consider the 2-byte value FFFF (signed −1). If it is logically right shifted once, the result is 7FFF which is +32, 767! Another type of shift can be used for signed values.

Text 3 Arithmetic shifts

These shifts are designed to allow signed numbers to be quickly multiplied and divided by powers of 2. They insure that the sign bit is treated correctly.

SAL Shift Arithmetic Left - This instruction is just a synonym for SHL. It is assembled into the exactly the same machine code as SHL. As long as the sign bit is not changed by the shift, the result will be correct.

SAR Shift Arithmetic Right - This is a new instruction that does not shift the sign bit (i.e. the msb) of its operand. The other bits are shifted as normal except that the new bits that enter from the left are copies of the sign bit (that is, if the sign bit is 1, the new bits are also 1). Thus, if a byte is shifted with this instruction, only the lower 7 bits are shifted. As for the other shifts, the last bit shifted out is stored in the carry flag.

1 mov ax, 0C123H

2 sal ax, 1 ; ax = 8246H, CF = 1

3 sal ax, 1 ; ax = 048CH, CF = 1

4 sar ax, 2 ; ax = 0123H, CF = 0

Text 4 Rotate shifts

The rotate shift instructions work like logical shifts except that bits lost off one end of the data are shifted in on the other side. Thus, the data is treated as if it is a circular structure. The two simplest rotate instructions are ROL and ROR which make left and right rotations, respectively. Just as for the other shifts, these shifts leave the a copy of the last bit shifted around in the carry flag.

1 mov ax, 0C123H

2 rol ax, 1 ; ax = 8247H, CF = 1

3 rol ax, 1 ; ax = 048FH, CF = 1

4 rol ax, 1 ; ax = 091EH, CF = 0

5 ror ax, 2 ; ax = 8247H, CF = 1

6 ror ax, 1 ; ax = C123H, CF = 1

There are two additional rotate instructions that shift the bits in the data and the carry flag named RCL and RCR. For example, if the AX register is rotated with these instructions, the 17-bits made up of AX and the carry flag are rotated.

1 mov ax, 0C123H

2 clc ; clear the carry flag (CF = 0)

3 rcl ax, 1 ; ax = 8246H, CF = 1

4 rcl ax, 1 ; ax = 048DH, CF = 1

5 rcl ax, 1 ; ax = 091BH, CF = 0

6 rcr ax, 2 ; ax = 8246H, CF = 1

7 rcr ax, 1 ; ax = C123H, CF = 0

Here is a code snippet that counts the number of bits that are “on” (i.e. 1) in the EAX register.

1 mov bl, 0 ; bl will contain the count of ON bits

2 mov ecx, 32 ; ecx is the loop counter

3 count_loop:

4 shl eax, 1 ; shift bit into carry flag

5 jnc skip_inc ; if CF == 0, goto skip_inc

6 inc bl

7 skip_inc:

8 loop count_loop

The above code destroys the original value of EAX (EAX is zero at the end of the loop). If one wished to retain the value of EAX, line 4 could be replaced with rol eax, 1.

4  Supply the sentences with the missing words.

To perform, multiplication, rotate shift, logical shifts, right shift, significant.

1 The SHL and SHR instructions are used … logical left and right shifts respectively.

2 Fast … and division are the most common uses of a shift operation.

3 The …instructions  work like … except hat bits lost off one end of the data are shifted in on the other side.

4 To divide by just 2, use a single…; to divide by 4 (22), shift right 2 places.

5 Shifts can be either toward the left (i.e. toward the most … bits) or toward the right (the least… bits).

5 Match the concepts with their definitions in the right column.

1 A logical shift

a) used to perform logical left an right shifts respectively.

2 SHL and SHR

b) can be used to multiply and divide unsigned values.

3 Logical shift

c) is assembled into  exactly the same machine code as SHL.

4 Arithmetic shift

d) is the simplest type of shift.

5 SAL Shift Arithmetic Left

e) is designed to allow signed numbers to be quickly multiplied and divided by powers of 2.

6 Insert a (an), the or no article where it is necessary.

1 … number of positions to shift can either be … constant or can be stored in … CL register.

2 … data is treated as if it is … circular structure.

3 … two additional rotate instructions shift the bits in … data and … carry flag named RCL and RCR.

4 These shifts leave … copy of the last bit shifted around in … carry flag.

5 This is … new instruction that does not shift … sign bit  (i.e. the msb) of its operand.

7 Use the verbs in brackets in the Passive voice.

1 These shifts (to design) to allow signed numbers to be quickly multiplied and divided by powers of 2.

2 They insure that the sign bit (to treat) correctly.

3 The original value of EAX ( to destroy) by the above code.

4 The difference of vleft - vright  (to compute)  and the flags (to set) accordingly.

5 Directives (not to translate) into machine code.  

8 Find the Gerund in the following sentences and define its tense form.

1 Deciphering the meanings of the numerical-coded instructions is tedious or humans.

2 Multiplying by 16 in hex is easy.

3 Intel solved this problem by using two 16-bit values to determine the address.

4 Porting assembly programs between different computer architecture is much more difficult than in HLL.

Comprehension

9 Ask the following questions on the text and let your group-mates answer them.

1 What language allows the programmer to manipulate individual bits of data?

2 What purposes are the SHL and SHR instructions used for?

3 What shifts allow signed numbers to be quickly multiplied and divided by powers of 2?

4 What is used for multiplication and division unsigned values?

5 What two additional rotate instructions do you know?

10 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

a common bit operation

a shift operation

the least significant bit

a shifted single byte number

a decimal system

shift instructions

the rotate shift instructions

additional rotate instructions

a logical shift

a code snippet

a signed value

a logical shift

fast multiplication and division

a circular structure

11 Translate into Russian in writing.

«Shift operators», «Logical shifts».

Unit 7

1 Learn the following words and word-combinations.

boolean, a

логический

bitwise, a

поразрядный, побитовый

truth table

таблица истинности

processor, n

процессор

content, n

содержание, содержимое 

corresponding, a 

соответственный

register, n

регистр, журнал

exclusive OR

исключающее ИЛИ

unary operation

одноместная операция, унарная операция, операция над одним операндом

binary operation

операция над двоичными числами, бинарная операция, операция с двумя операндами

 store, v

запоминать, хранить, сохранять

subtraction, n 

вычитание

implement, v

выполнять, осуществлять, вводить в действие

remainder of a division

остаток от деления

snippet of code

Фрагмент, отрывок, кусок кода

quotient, n

частное, отношение

loop counter

счётчик цикла

machine code

машинный код, программа на машинном языке

arbitrary bit

произвольный, случайный бит

operator, n

Оператор

operand, n

операнд, компонента операции

 

2 Learn  the   following  abbreviations.

CMP (control microprocessor) – управляющий микропроцессор;

ZF (Zero Flag) – флаг нуля (разряд в регистре состояния микропроцессора, указывающий, что результат операции равен нулю).

3 Read the texts bellow and report on the following concepts:

1. «The AND operation»;

2. «The NOT operation»;

3. «The TEST instruction».

Reading

Text 1 Boolean Bitwise Operations

There are four common boolean operators: AND, OR, XOR and NOT. A truth table shows the result of each operation for each possible value of its operands.

The AND operation

The result of the AND of two bits is only 1 if both bits are 1, else the result is 0 as the truth table in Table 3.1 shows.

Processors support these operations as instructions that act independently on all the bits of data in parallel. For example, if the contents of AL and BL are ANDed together, the basic AND operation is applied to each of the 8 pairs of corresponding bits in the two registers as Figure 3.2 shows. Below is a code example:

1 mov ax, 0C123H

2 and ax, 82F6H ; ax = 8022H

The OR operation

The inclusive OR of 2 bits is 0 only if both bits are 0, else the result is 1 as the truth table in Table 3.2 shows. Below is a code example:

1 mov ax, 0C123H

2 or ax, 0E831H ; ax = E933H

The XOR operation

The exclusive OR of 2 bits is 0 if and only if both bits are equal, else the result is 1 as the truth table in Table 3.3 shows. Below is a code example:

1 mov ax, 0C123H

2 xor ax, 0E831H ; ax = 2912H

The NOT operation

The NOT operation is a unary operation (i.e. it acts on one operand, not two like binary operations such as AND). The NOT of a bit is the opposite value of the bit as the truth table in Table 3.4 shows. Below is a code example:

1 mov ax, 0C123H

2 not ax ; ax = 3EDCH

Note that the NOT finds the one’s complement. Unlike the other bitwise operations, the NOT instruction does not change any of the bits in the FLAGS register.

Text 2 The TEST instruction

The TEST instruction performs an AND operation, but does not store the result. It only sets the FLAGS register based on what the result would be (much like how the CMP instruction performs a subtraction but only sets FLAGS). For example, if the result would be zero, ZF would be set.

Turn on bit i                

OR the number with 2i (which is the binary number with just bit i on)

Turn off bit i               

AND the number with the binary number with only bit i off. This operand is often called a mask

Complement bit i        

XOR the number with 2i

Table 3.5: Uses of boolean operations

Text 3 Uses of bit operations

Bit operations are very useful for manipulating individual bits of data without modifying the other bits. Table 3.5 shows three common uses of these operations. Below is some example code, implementing these ideas.

1 mov ax, 0C123H

2 or ax, 8 ; turn on bit 3, ax = C12BH

3 and ax, 0FFDFH ; turn off bit 5, ax = C10BH

4 xor ax, 8000H ; invert bit 31, ax = 410BH

5 or ax, 0F00H ; turn on nibble, ax = 4F0BH

6 and ax, 0FFF0H ; turn off nibble, ax = 4F00H

7 xor ax, 0F00FH ; invert nibbles, ax = BF0FH

8 xor ax, 0FFFFH ; 1’s complement, ax = 40F0H

The AND operation can also be used to find the remainder of a division by a power of two. To find the remainder of a division by 2i, AND the number with a mask equal to 2i −1. This mask will contain ones from bit 0 up to bit i − 1. It is just these bits that contain the remainder. The result of the AND will keep these bits and zero out the others. Next is a snippet of code that finds the quotient and remainder of the division of 100 by 16.

1 mov eax, 100 ; 100 = 64H

2 mov ebx, 0000000FH ; mask = 16 - 1 = 15 or F

3 and ebx, eax ; ebx = remainder = 4

Using the CL register it is possible to modify arbitrary bits of data. Next is an example that sets (turns on) an arbitrary bit in EAX. The number of the bit to set is stored in BH.

1 mov bl, 0 ; bl will contain the count of ON bits

2 mov ecx, 32 ; ecx is the loop counter

3 count_loop:

4 shl eax, 1 ; shift bit into carry flag

5 adc bl, 0 ; add just the carry flag to bl

6 loop count_loop

Figure 3.3: Counting bits with ADC

1 mov cl, bh ; first build the number to OR with

2 mov ebx, 1

3 shl ebx, cl ; shift left cl times

4 or eax, ebx ; turn on bit

Turning a bit off is just a little harder.

1 mov cl, bh ; first build the number to AND with

2 mov ebx, 1

3 shl ebx, cl ; shift left cl times

4 not ebx ; invert bits

5 and eax, ebx ; turn off bit

Code to complement an arbitrary bit is left as an exercise for the reader.

It is not uncommon to see the following puzzling instruction in a 80x86 program:

xor eax, eax ; eax = 0

A number XOR’ed with itself always results in zero. This instruction is used because its machine code is smaller than the corresponding MOV instruction.

Exercises

4 Supply the   sentences with the missing   words.

Store, operators, instructions, bitwise, exclusive.

1 There are four common boolean : AND, OR, XOR and NOT.

2 Processors support AND, OR, XOR and NOT operations as that act independently on all the bits of data.

3 The OR of 2 bits is 0 if and only if both bits are equal, else the result is 1.

4 Unlike the other operations, the NOT instruction does not change any of the bits in the FLAGS register.

5 The TEST instruction performs an AND operation, but does not the result.

5 Match the concepts with their definitions.

1 A truth table

a) is an instruction that performs an AND operation, but does not store the result.

2 The inclusive OR of 2 bits

b) are very useful for manipulating individual bits of data without modifying the other bits.

3 The NOT operation

c) is a unary operation (i.e. it acts on one operand, not two like binary operations such as AND).

4 Bit operations

d) is 0 only if both bits are 0, else the result is 1.

5 The TEST instruction

e) is a table that shows the result of each operation for each possible value of its operands.

 

6 Insert a (an), the or no article where it is necessary.

1 There is no … easy way to use … MOV instruction.

2  In assembly, all data has … specified size.

3 When performing …addition in … two’s complement operation, …addition of …leftmost bit may produce … carry.

4 …signed byte can be used to represent …numbers −128 to +127.

7 Insert  prepositions where it is necessary.

1 A truth table shows the result … each operation … each possible value… its operands.

2 The NOT instruction does not change any … the bits … the FLAGS register.

3 Bit operations are very useful … manipulating individual bits … data

4 The NOT operation acts … one operand, not two like binary operations such as AND).

5 The AND operation can also be used to find the remainder … a division … a power of two.

8 Find the Infinitive in the following sentences and define its function.

1 Data directives are used in data segments to define room for memory.

2 This lets the C system set up the program to run correctly in protected mode.

3 It is very important to know this convention to interface C and assembly.

4 The equ directive can be used to define a symbol.

Comprehension

9 Ask the following questions about the text and let your group-mates answer them.

1 How many common boolean operators do you know?

2 What does a truth table show?

3 What is the result of the AND of two bits?

4 What is the inclusive OR of 2 bits?

5 What is the NOT of a bit?

6 The NOT operation is a binary operation, isn’t it?

7 Are bit operations very useful for manipulating individual bits of data?

8 Can the AND operation also be used to find the remainder of a division by a power of two?

9 Is it possible to modify arbitrary bits of data using the CL register ?

10 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

a processor

binary operations

to contain

to modify

to support

8 pairs of corresponding bits

arbitrary bits of data

the remainder

bit operations

to store the result

bitwise operations

common boolean operators

the opposite value

an unary operation

11 Translate into Russian in writing.

Text 3 «Uses of bit operations».

12 Translate into English.

1 Таблица истинности полностью описывает логическую функцию перечислением всех возможных комбинаций входных значений (сигналов) и соответствующих каждой комбинации значений (сигналов) на выходе.

2 Операция И над двоичными разрядами операндов (0, 1) или над логическими величинами (true, false) возвращает значение "истина" только, если оба операнда 1 или оба истинны.

3 Операция ИЛИ - бинарная логическая операция, истинная только тогда, когда истинен хотя бы один из операндов.

Unit 8

1 Learn the following words and word-combinations.

access, n

доступ

binary, a

бинарный

bit, n

бит

bitwise, adv

побитно

byte, n

байт

compiler, n

компилятор

data, n

данные

division, n

деление

electronic circuit

электрическая цепь

function, n

функция

integer, n

целое

memory, n

память

multiplication, n

умножение

operator, n

оператор

parameter, n

параметр

pointer, n

указатель

processor, n

процессор

register, n

регистр

representation, n

представление

shift, n

перемещение

string, n

строка

unsigned, a

беззнаковое

 

2 Learn  the   following  abbreviations.

POSIX (Portable Operating System Interface for Unix) – переносимый интерфейс операционной системы для Unix;

CPU (Central Processing Unit) – центральное вычислительное устройство (центральный процессор);

API (Application Programming Interface) – интерфейс программирования приложений.

3 Report on the following concept.

«The bitwise operators of C».

Reading

Manipulating bits in C

TEXT 1 The bitwise operators of C

Unlike some high-level languages, C does provide operators for bitwise operations. The AND operation is represented by the binary & operator. The OR operation is represented by the binary | operator. The XOR operation is represetned by the binary ^ operator. And the NOT operation is represented by the unary ~ operator.

The shift operations are performed by C’s << and >> binary operators. The << operator performs left shifts and the >> operator performs right shifts. These operators take two operands. The left operand is the value to shift and the right operand is the number of bits to shift by. If the value to shift is an unsigned type, a logical shift is made. If the value is a signed type (like int), then an arithmetic shift is used. Below is some example C code using these operators:

1 short int s ; /_ assume that short int is 16−bit _/

2 short unsigned u;

3 s = −1; /_ s = 0xFFFF (2’s complement) _/

4 u = 100; /_ u = 0x0064 _/

5 u = u | 0x0100; /_ u = 0x0164 _/

6 s = s & 0xFFF0; /_ s = 0xFFF0 _/

7 s = s ˆ u; /_ s = 0xFE94 _/

8 u = u << 3; /_ u = 0x0B20 (logical shift ) _/

9 s = s >> 2; /_ s = 0xFFA5 (arithmetic shift ) _/

TEXT 2 Using bitwise operators in C

The bitwise operators are used in C for the same purposes as they are used in assembly language. They allow one to manipulate individual bits of data and can be used for fast multiplication and division. In fact, a smart C compiler will use a shift for a multiplication like,  x *= 2, automatically.

Many operating system API2’s (such as POSIX 3 and Win32) contain functions which use operands that have data encoded as bits. For example, POSIX systems maintain file permissions for three different types of users: user (a better name would be owner), group and others. Each type of user can be granted permission to read, write and/or execute a file. To change the permissions of a file requires the C programmer to manipulate individual bits. POSIX defines several macros to help (see Table 3.6). The chmod function can be used to set the permissions of file. This function takes two parameters, a string with the name of the file to act on and an integer with the appropriate bits set for the desired permissions. For example, the code below sets the permissions to allow the owner of the file to read and write to it, users in the group to read the file and others have no access. chmod(”foo”, S IRUSR | S IWUSR | S IRGRP);

The POSIX stat function can be used to find out the current permission bits for the file. Used with the chmod function, it is possible to modify some of the permissions without changing others. Here is an example that removes write access to others and adds read access to the owner of the file. The other permissions are not altered.

1 struct stat file stats ; /_ struct used by stat () _/

2 stat (”foo”, & file stats ); /_ read file info .

3 file stats .st mode holds permission bits _/

4 chmod(”foo”, ( file stats .st mode & ˜S IWOTH) | S IRUSR);

TEXT 3 Big and Little Endian Representations

Chapter 1 introduced the concept of big and little endian representations of multibyte data. However, the author has found that this subject confuses many people. This section covers the topic in more detail.

The reader will recall that endianness refers to the order that the individual bytes (not bits) of a multibyte data element is stored in memory. Big endian is the most straightforward method. It stores the most significant byte first, then the next significant byte and so on. In other words the big bits are stored first. Little endian stores the bytes in the opposite order (least significant first). The x86 family of processors use little endian representation.

As an example, consider the double word representing 1234567816. In big endian representation, the bytes would be stored as 12 34 56 78. In little endian represenation, the bytes would be stored as 78 56 34 12.

The reader is probably asking himself right now, why any sane chip designer would use little endian representation? Were the engineers at Intel sadists for inflicting this confusing representations on multitudes of programmers? It would seem that the CPU has to do extra work to store the bytes backward in memory like this (and to unreverse them when read back in to memory). The answer is that the CPU does not do any extra work to write and read memory using little endian format. One has to realize that the CPU is composed of many electronic circuits that simply work on bit values. The bits (and bytes) are not in any necessary order in the CPU.

Consider the 2-byte AX register. It can be decomposed into the single byte registers: AH and AL. There are circuits in the CPU that maintain the values of AH and AL. Circuits are not in any order in a CPU. That is, the circuits for AH are not before or after the circuits for AL. A mov instruction that copies the value of AX to memory copies the value of AL then AH. This is not any harder for the CPU to do than storing AH first.

The same argument applies to the individual bits in a byte. They are not really in any order in the circuits of the CPU (or memory for that matter). However, since individual bits can not be addressed in the CPU or memory, there is no way to know (or care about) what order they seem to be kept internally by the CPU.

The C code in Figure 3.4 shows how the endianness of a CPU can be determined. The p pointer treats the word variable as a two element character array. Thus, p[0] evaluates to the first byte of word in memory which depends on the endianness of the CPU.

1 unsigned invert endian ( unsigned x )

2 {

3 unsigned invert ;

4 const unsigned char _ xp = (const unsigned char _) &x;

5 unsigned char _ ip = (unsigned char _) & invert;

6

7 ip [0] = xp [3]; /_ reverse the individual bytes _/

8 ip [1] = xp [2];

9 ip [2] = xp [1];

10 ip [3] = xp [0];

11

12 return invert ; /_ return the bytes reversed _/

13 }

Exercises

4  Supply the   sentences with the missing   words.

Shift, data, bits, multiplication, unsigned, operators, division.

  1.  Unlike some high-level languages, C does provide … for bitwise operations.
  2.  The … operations are performed by C’s << and >> binary operators.
  3.  If the value to shift is an … type, a logical shift is made.
  4.  They allow one to manipulate individual bits of … and can be used for fast … and … .
  5.  To change the permissions of a file requires the C programmer to manipulate individual … .

5 Match  the  concepts  with  their  definitions.

 1 POSIX systems

a) are used in C for the same purposes as they are used in assembly language.

2  right operand

b) is represented by the binary & operator.

3 bitwise operators

c) is the number of bits to shift by.

4 AND operation

d) can be used to find out the current permission bits for the file.

5 POSIX stat function

e) are performed by C’s << and >> binary operators.

6 shift operation

f) maintain file permissions for three different types of users: user (a better name would be owner), group and others.

6 Insert  prepositions where it is necessary.

1 The left operand is the value to shift and the right operand is the number … bits to shift ….

2 The bitwise operators allow one to manipulate individual bits … data and can be used … fast multiplication and division.

3 Each type … user can be granted … permission to read, write and/or execute a file.

4 This function takes a string … the name … the file to act … and an integer … the appropriate bits set … the desired permissions.

7 Put the verbs in brackets into a proper tense form.

1 The << operator (to perform)  left shifts and the >> operator (to perform)  right shifts.

2 Unlike the other bitwise operations, the NOT instruction (not to change)  any of the bits in the FLAGS register.

3 The same argument (to apply) to the individual bits in a byte.

4 Thus, p[0] (to evaluate) to the first byte of word in memory which (to depend) on the endianness of the CPU.

8 Find the Gerund in the following sentences and explain its function.

1 Linking is the process of combining the machine code and data in object files and library files together to create an executable file.

2 The one’s complement of a number is found by reversing each bit in the number.

3 There is a handy trick to finding the one’s complement of a number in hexadecimal without converting it to binary.

4 In two complement’s notation, computing the two’s complement is equivalent to negating a number.

5 Code labels are defined by placing them in the code segment in front of the statement they label.

6 There is no formula for doing this.

Comprehension

9 Ask the following questions about the text and let your group-mates answer them.

1. What does the C provide?

2. Are there any circuits in the CPU that maintain the values of AH and AL?

3. How is the XOR operation represented?

4. How are the shift operations performed?

5. The bitwise operators are used in C for the same purposes as they are used in assembly language, aren’t they?

6. What does the << operator perform?

7. What must C programmer do to change the permissions of a file?

8. What is the left operand?

9. What does a code in example set?

10. How is the CPU composed?

10 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

shift operations

a value

an unsigned type

an arithmetic shift

a logical shift

bitwise operators

fast multiplication an division

a smart C compiler

encoded data

file permissions

desired permissions

Access

multibyte data

sane chip designer

11 Translate into Russian in writing. 

TEXT 2 «Using bitwise operators in C».

12 Translate into English.

1 Обычно программа на языке С организована в одном или нескольких исходных файлах или модулях.

2 Файл начинается с комментария, который описывает цель модуля и обеспечивает другую информацию, такую как имя автора и дату.

3 Каждый файл имеет схожую структуру с комментариями, директивами препроцессора, объявлениями переменных и функций и их определениями.

Unit 9

1 Learn the following words and word-combinations.

iteration, n

итерация, повторение, шаг цикла

loop, n

цикл

original value 

первоначальное значение

binary representation

двоичное представление, запись в двоичной системе (счисления)

definition, n

определение, описание

data, n 

данные, информация

initialize, v

инициализировать, устанавливать в исходное состояние

lookup table

таблица поиска, таблица преобразования, справочная таблица, таблица соответствия

approach, n

подход, метод

precompute, v

предварительно вычислять

store, v

запоминать, хранить, сохранять

loop unrolling

развертывание цикла, превращение цикла в линейную последовательность команд (может производиться для ускорения исполнения программы, поскольку сокращает каждый цикл на несколько команд)

array, n

массив (данных)

function , n

функция

variable, n

переменная (величина)

pointer,  n

указатель

reference, n

ссылка

increment, n

инкремент, приращение, увеличение

constant, n

константа, постоянная величина

odd position

нечетная позиция

technique, n

техника, технические приёмы, методика

smart compiler

компилятор с развитой логикой

final result

конечный результат

implementation, n

выполнение, исполнение, осуществление, реализация

2 Read the texts bellow and report on the following concept.

«Method two».

Reading

Text 1 Counting Bits

Earlier a straightforward technique was given for counting the number of bits that are “on” in a double word. This section looks at other less direct methods of doing this as an exercise using the bit operations discussed in this chapter.

Method one

The first method is very simple, but not obvious. Figure 3.6 shows the code.

How does this method work? In every iteration of the loop, one bit is turned off in data. When all the bits are off (i.e. when data is zero), the loop stops. The number of iterations required to make data zero is equal to the number of bits in the original value of data.

Line 6 is where a bit of data is turned off. How does this work? Consider the general form of the binary representation of data and the rightmost 1 in this representation. By definition, every bit after this 1 must be zero. Now, what will be the binary representation of data - 1? The bits to the left of the rightmost 1 will be the same as for data, but at the point of the rightmost 1 the bits will be the complement of the original bits of data. For example:

data = xxxxx10000

data - 1 = xxxxx01111

1 static unsigned char byte bit count [256]; /_ lookup table _/

2

3 void initialize count bits ()

4 {

5 int cnt , i , data;

6

7 for ( i = 0; i < 256; i++ ) {

8 cnt = 0;

9 data = i ;

10 while( data != 0 ) { /_ method one _/

11 data = data & (data − 1);

12 cnt++;

13 }

14 byte bit count [ i ] = cnt ;

15 }

16 }

17

18 int count bits ( unsigned int data )

19 {

20 const unsigned char _ byte = ( unsigned char _) & data;

21

22 return byte bit count [byte [0]] + byte bit count [byte [1]] +

23 byte bit count [byte [2]] + byte bit count [byte [3]];

24 }

Figure 3.7: Method Two

where the x’s are the same for both numbers. When data is AND’ed with data - 1, the result will zero the rightmost 1 in data and leave all the other bits unchanged.

Text 2 Method two

A lookup table can also be used to count the bits of an arbitrary double word. The straightforward approach would be to precompute the number of bits for each double word and store this in an array. However, there are two related problems with this approach. There are roughly 4 billion double word values! This means that the array will be very big and that initializing it will also be very time consuming. (In fact, unless one is going to actually use the array more than 4 billion times, more time will be taken to initialize the array than it would require to just compute the bit counts using method one!)

A more realistic method would precompute the bit counts for all possible byte values and store these into an array. Then the double word can be split up into four byte values. The bit counts of these four byte values are looked up from the array and sumed to find the bit count of the original double word. Figure 3.7 shows the to code implement this approach.

The initialize count bits function must be called before the first call to the count bits function. This function initializes the global byte bit count array. The count bits function looks at the data variable not as a double word, but as an array of four bytes. The dword pointer acts as a pointer to this four byte array. Thus, dword[0] is one of the bytes in data (either the least significant or the most significant byte depending on if the hardware is little or big endian, respectively.) Of course, one could use a construction like:

(data >> 24) & 0x000000FF

to find the most significant byte value and similar ones for the other bytes; however, these constructions will be slower than an array reference.

One last point, a for loop could easily be used to compute the sum on lines 22 and 23. But, a for loop would include the overhead of initializing a loop index, comparing the index after each iteration and incrementing the index. Computing the sum as the explicit sum of four values will be faster. In fact, a smart compiler would convert the for loop version to the explicit sum. This process of reducing or eliminating loop iterations is a compiler optimization technique known as loop unrolling.

Text 3 Method three

There is yet another clever method of counting the bits that are on in data. This method literally adds the one’s and zero’s of the data together. This sum must equal the number of one’s in the data. For example, consider counting the one’s in a byte stored in a variable named data. The first step is to perform the following operation:

data = (data & 0x55) + ((data >> 1) & 0x55);

What does this do? The hex constant 0x55 is 01010101 in binary. In the first operand of the addition, data is AND’ed with this, bits at the odd bit positions are pulled out. The second operand ((data >> 1) & 0x55) first moves all the bits at the even positions to an odd position and uses the same mask to pull out these same bits. Now, the first operand contains the odd bits and the second operand the even bits of data. When these two operands are added together, the even and odd bits of data are added together. For example, if data is 101100112, then:

1 int count bits (unsigned int x )

2 {

3 static unsigned int mask[] = { 0x55555555,

4 0x33333333,

5 0x0F0F0F0F,

6 0x00FF00FF,

7 0x0000FFFF };

8 int i ;

9 int shift ; /_ number of positions to shift to right _/

10

11 for ( i=0, shift =1; i < 5; i++, shift _= 2 )

12 x = (x & mask[i ]) + ( ( x >> shift) & mask[i ] );

13 return x;

14 }

Figure 3.8: Method 3

The addition on the right shows the actual bits added together. The bits of the byte are divided into four 2-bit fields to show that actually there are four independent additions being performed. Since the most these sums can be is two, there is no possibility that the sum will overflow its field and corrupt one of the other field’s sums.

Of course, the total number of bits have not been computed yet. However, the same technique that was used above can be used to compute the total in a series of similar steps. The next step would be:

data = (data & 0x33) + ((data >> 2) & 0x33);

Continuing the above example (remember that data now is 011000102):

Now there are two 4-bit fields to that are independently added.

The next step is to add these two bit sums together to form the final result:

data = (data & 0x0F) + ((data >> 4) & 0x0F);

Using the example above (with data equal to 001100102):

Now data is 5 which is the correct result. Figure 3.8 shows an implementation of this method that counts the bits in a double word. It uses a for loop to compute the sum. It would be faster to unroll the loop; however, the loop makes it clearer how the method generalizes to different sizes of data.

Exercises

3 Supply the   sentences with the missing   words.

Loop, store, precompute, an array, the odd bit positions, iterations.

1 The number of … required to make data zero is equal to the number of bits in the original value of data.

2 When all the bits are off (i.e. when data is zero), the … stops.

3 A more realistic method would … the bit counts for all possible byte values and … these into an array.

4 The count bits function looks at the data variable not as a double word, but as … of four bytes.

5 In the first operand of the addition, data is AND’ed with this, bits at … are pulled out.

4 Match the concepts with their definitions.

1 a loop

a) is a series of instructions in a program, performed repeatedly until some specified condition is satisfied

2 a lookup table

b) is the smallest unit of information, a single digit of binary notation, represented either by 0 or by 1

3 loop unrolling

c) is a table that can also be used to count the bits of an arbitrary double word

4 a variable

d) is a compiler optimization technique that reduces or eliminates loop iterations

5 a bit

e) a named unit of storage that can be changed to any of a set of specified values during execution of a program

5 Insert  prepositions where it is necessary.

1 The count bits function looks … the data variable not as a double word, but as an array … four bytes. 

2 … every iteration … the loop, one bit is turned … … data.

3 The double word can be split … four byte values.

4 Consider the general form … the binary representation … data and the rightmost 1 … this representation.

6 Put the verbs in brackets into a proper tense form.

1 The count bits function (to look) at the data variable not as a double word, but as an array of four bytes.

2 Unlike some high-level languages, C (to provide) operators for bitwise operations.

3 These operators ( to take)  two operands.

4 This function (to take) two parameters, a string with the name of the file to act on and an integer with the appropriate bits set for the desired permissions.

5 A mov instruction that (to copy) the value of AX to memory (to copy) the value of AL then AH.

7 Use Complex Object in the following sentences according to the following model.

Model:

1  I know that the simplest multidimensional array is a two dimensional one.

   The simplest multidimensional array is known to be a two dimensional one.

1 We expected that a two dimensional array is a grid of elements.

2 We believe that an array is a contiguous block of list of data in memory.

3 Pete discovered that the row wise representation of multidimensional arrays had a direct effect in C programming.

4 She believed that processors support these operations as instructions.

Comprehension

8 Ask the following questions about the text and let your group-mates answer them.

1 How many methods of counting the bits do you know?

2 How does the first method work?

3 The number of iterations required to make data zero is equal to the number of bits in the original value of data, isn’t it?

4 Can a lookup table be used to count the bits of an arbitrary double word?

5 When must the initialize count bits function be called?

6 What does this function initialize?

7 Would a smart compiler convert the for loop version to the explicit sum?

8 What does the third method literally do?

9 Is there any possibility that the sum will overflow its field and corrupt one of the other field’s sums in the third method?

9 Find Russian equivalents for the following words and  word-combinations and then put them down in  the right column.

a straightforward technique

iteration of the loop

the binary representation

an arbitrary double word

an array

the double word

the bit count

the count bit function

the most significant byte value

an array reference

the overhead of initializing a loop index

a compiler optimization technique

an even position

an odd position

the original double word

to overflow

to corrupt

10 Translate into Russian in writing.

«Method three».

11 Translate into English.

 Оператор цикла for работает так:

- вычисляется начальное выражение. Это происходит единственный раз при первом выполнении оператора for;

- проверяется условие. Если условие истинно, то выполняется заданный оператор в теле цикла. Если условие ложно, то происходит выход из цикла и выполняется следующий после цикла оператор;

- после выполнения заданного оператора происходит изменение счетчика;

- последовательность действий повторяется снова с проверки условия.

Unit 10

1 Learn the following words and word-combinations.

subprogram, n

подпрограмма

modular program

модульная программа

calling convention

соглашение о вызовах

register-based calling convention  

соглашение о регистровых вызовах

built-in support

встроенная поддержка

subprogram call

вызов подпрограммы

double word

двойное слово

stack, n

стек

high level programming languages

языки программирования высокого уровня

push, v

помещать

pointer, n

указатель

2 Read the texts below and be ready to report on the following:

1. «Subprograms»;

2. «The stack».

Reading

Text 1 Subprograms

This chapter looks at using subprograms to make modular programs and to interface with high level languages (like C). Functions and procedures are high level language examples of subprograms.

The code that calls a subprogram and the subprogram itself must agree on how data will be passed between them. These rules on how data will be passed are called calling conventions. A large part of this chapter will deal with the standard C calling conventions that can be used to interface assembly subprograms with C programs. This (and other conventions) often passes the addresses of data (i.e. pointers) to allow the subprogram to access the data in memory.

Text 2 Simple Subprogram Example

A subprogram is an independent unit of code that can be used from different parts of a program. In other words, a subprogram is like a function in C. A jump can be used to invoke the subprogram, but returning presents a problem. If the subprogram is to be used by different parts of the program, it must return back to the section of code that invoked it. Thus, the jump back from the subprogram can not be hard coded to a label. The code below shows how this could be done using the indirect form of the JMP instruction. This form of the instruction uses the value of a register to determine where to jump to (thus, the register acts much like a function pointer in C.) Here is the first program from chapter 1 rewritten to use a subprogram.

sub1.asm

The get int subprogram uses a simple, register-based calling convention. It expects the EBX register to hold the address of the DWORD to store the number input into and the ECX register to hold the code address of the instruction to jump back to. In lines 25 to 28, the ret1 label is used to compute this return address. In lines 32 to 34, the $ operator is used to compute the return address. The $ operator returns the current address for the line it appears on. The expression $ + 7 computes the address of the MOV instruction on line 36.

Both of these return address computations are awkward. The first method requires a label to be defined for each subprogram call. The second method does not require a label, but does require careful thought. If a near jump was used instead of a short jump, the number to add to $ would not be 7! Fortunately, there is a much simpler way to invoke subprograms. This method uses the stack.

Text 3 The Stack

Many CPU’s have built-in support for a stack. A stack is a Last-In First-Out (LIFO) list. The stack is an area of memory that is organized in this fashion. The PUSH instruction adds data to the stack and the POP instruction removes data. The data removed is always the last data added (that is why it is called a last-in first-out list).

The SS segment register specifies the segment that contains the stack (usually this is the same segment data is stored into). The ESP register contains the address of the data that would be removed from the stack. This data is said to be at the top of the stack. Data can only be added in double word units. That is, one can not push a single byte on the stack.

The PUSH instruction inserts a double word on the stack by subtracting 4 from ESP and then stores the double word at [ESP]. The POP instruction reads the double word at [ESP] and then adds 4 to ESP. The code below demostrates how these instructions work and assumes that ESP is initially 1000H.

The stack can be used as a convenient place to store data temporarily. It is also used for making subprogram calls, passing parameters and local variables.

The 80x86 also provides a PUSHA instruction that pushes the values of EAX, EBX, ECX, EDX, ESI, EDI and EBP registers (not in this order). The POPA instruction can be used to pop them all back off.

Exercises

3 Supply the   sentences with the missing   words.

Functions and procedures, an independent unit of code, a jump, a label, the PUSH instruction, the POP instruction.

1 … … are high level language examples of subprograms.

2. A subprogram is ... ... … that can be used from different parts of a program.

3. ... can be used to invoke the subprogram, but returning presents a problem.

4. The first method requires ... to be defined for each subprogram call.

5. ... adds data to the stack and ... removes data.

4 Match the concepts with their definitions.

1 Calling conventions

a) is an independent unit of code that can be used from different parts of a program.

2 Functions and procedures

b) is an area of memory that is organized in LIFO fashion.

3 A subprogram

c) is instruction for adding data to the stack

4 The stack

d) are high level language examples of subprograms

5 PUSH instruction

e) are rules on how data will be passed

5 Put the verbs in brackets into a proper tense form.

1 The PUSH instruction (to insert) a double word on the stack by subtracting 4 from ESP and then stores the double word at [ESP].

2 The code below (to show) how this could be done using the indirect form of the JMP instruction.

3 The first method (to require) a label to be defined for each subprogram call.

4 There (to be)  a much simpler way to invoke subprograms. This method (to use) the stack.

5 The second method (not to require) a label.

6 Fill in a (an), the or no prepositions.

1 … first method is very simple, but not obvious.

2 … number of iterations required to make data zero is equal to … number of bits in … original value of data.

3 … lookup table can also be used to count … bits of … arbitrary double word.

4 … count bits function looks at … data variable not as … double word, but as … array of four bytes.

5 … << operator performs left shifts and … >> operator performs right shifts.

7 Use the following sentences in the Passive voice.

1 This function initializes the global byte bit count array.

2 Because of these properties, arrays allow efficient access of the data.

3 Memory stores contiguously each row of the two dimensional array.

4 Figure 3.8 shows an implementation of this method.

Comprehension

8 Explain what part of speech the words with  ing-endings are. Define their forms and the functions they perform.

1 A straightforward technique was given for counting the number of bits.

2 This section looks at other less direct methods of doing this as an exercise using the bit operations discussed in this chapter.

3 This means that the array will be very big and that initializing it will also be very time consuming.

4  But a for loop would include the overhead of initializing a loop index, comparing the index after each iteration and incrementing the index.

9 Ask the following questions about the text and let your group-mates answer them.

1. What are subprograms used for?

2. Do the code that calls a subprogram and the subprogram itself must agree on how data between them will be passed?

3. How can a jump be used to invoke the subprogram?

4. What is a register-based calling convention?

5. What fashion is the stack organized in?

6. What do the POP and the PUSH instructions usually do?

10 Find Russian equivalents for the verbs you come across while reading technical literature. Put them down in the right column.

to deal with

to store data

to access

to invoke

to insert

to add data

to interface

to call data

to pass data

to return current address 

to determine

to hold the code address of the instruction

to jump back

to remove data

to pass parameters and local variables

to push the values

to require a label

to define

11 Translate into Russian in writing.

«Simple Subprogram Example».

12 Translate into English.

1 Язык ассемблер осуществляет символическое представление числовых машинных кодов и других констант, необходимых для программирования специфической архитектуры ЦПУ.

2 Как правило, современный ассемблер создает объектный код, переводя мнемонику команды трансляции в коды операции, и определяя  символические наименования для местоположений памяти и других объектов.

3 Команды (операторы) в ассемблере вообще очень просты, в отличие от команд(операторов) на языках высокого уровня.

LIST OF ENGLISH-RUSSIAN TERMS

A

access

обращаться, иметь доступ

addition, n

суммирование

approach, n

подход, метод

approximation, n

аппроксимация, приближение

arbitrary

произвольный

arbitrary bit

произвольный, случайный бит

arithmetic shift

арифметический сдвиг

array, n

массив (данных)

array instruction  

Команда работы с массивом

assembly

собирать

assemble, v

собирать, компоновать, транслировать программу

assembly language

язык ассемблера

attribute extension

расширение свойства (признака, атрибута)

available

доступный

B

binary, a

Бинарный, двоичное число

binary operation

операция над двоичными числами, бинарная операция, операция с двумя операндами

binary representation

двоичное представление, запись в двоичной системе (счисления)

binary system

2-ная система исчисления

bit, n

Бит

bitwise, a

поразрядный, побитовый

boolean, a

логический

boundary, n

граница (предел)

branch, n

ветвь(исп. в условных операторах)

built-in support

встроенная поддержка

byte, n

Байт

C

calling convention

соглашение о вызовах

code snippet

фрагмент кода

columnwise representation

представление в виде столбцов

compiler, n

компилятор

complicate, (v)

затруднять, осложнять, усложнять;

compute, v

вычислять, рассчитывать

condition, n

условие, состояние, ситуация

constant, n

константа, постоянная величина

content, n

содержание, содержимое

convention, n

соглашение

convert, v

конвертировать, преобразовывать

consider, v

рассматривать, обсуждать, полагать

contiguous

соприкасающийся, смежный, граничащий, прилегающий

coprocessor

сопроцессор

corresponding, a

соответственный

D

data, n

данные, информация

data segment

сегмент данных

decimal  

десятичное число

decimal digits  

десятичные цифры

decimal system

10-ная  система исчисления

deciphering, n

декодирование

decrease, (n)

уменьшение, убывание, убавление, сокращение;

decrement , n

декремент, убывание, уменьшение

default type

тип по-умолчанию

define, v

определять

definition, n

определение, описание

denormalized numbers

денормализованные числа

direction flag

флаг управления

directive, n

директива

designed

разработанный

determine, v

определять, вычислять, решать, устанавливать

device, n

устройство

digit, n

Цифра

direct, a

Прямой

directive, n

директива

divide   

разделить

division, n

Деление

double word

двойное слово

drawback,(n)

недостаток, отрицательная сторона;

dump, n

дамп, вывод содержимого памяти

E

efficiently, adv

эффективно, продуктивно

efficient access

эффективный доступ

electronic circuit

электрическая цепь

encode, v

кодировать, закодировать

equivalent, n

эквивалент, равноценный

essential, a

Главный, существенный, присущий

exclusive OR

исключающее ИЛИ

executable program

выполняемая программа

explicitly , adv

однозначно, ясно, точно

explicitly assign

однозначно\явно установленный

exponent, n

экспонента, показатель степени

extension, n

расширение

F

final result

конечный результат

flexible, a

Гибкий

floating point

число с плавающей точкой

format string

форматирующая строка

fortunately, adv

к Счастью

fraction

Дробь

fractional part

дробная часть

frame, n

фрэйм

frequency, n

Частота

function, n

Функция

G

generalize,v

обобщать, сводить к общим законам

H

hardware

аппаратные средства

hexadecimal system

16-ная  система исчисления

high level code

код высокого уровня

high level programming languages

языки программирования высокого уровня

I

Implementation, n

внедрение, ввод в работу, реализация.

increment, n

инкремент, приращение, увеличение

Instruction, n

команда, инструкция, программа действий.

incidently (~ially), adv

случайно

increase, (n)

расширение, увеличение;

index register

индексный регистр

indirect, a

косвенный

infinite loop  

бесконечный цикл

infinite precision

бесконечная точность

initialize, v

инициализировать, устанавливать в исходное состояние

initialized array

инициализированный массив

(массив с присвоенныйми значениями элементов)

Instruction, n

команда, инструкция, программа действий.

integer, n

Целое

integral part  

целая часть

integer pointer

целочисленный указатель

integer representation  

целочисленное представление;

interface

интерфейс

iteration, n

Итерация, повторение, шаг цикла

K

Keyword, n

ключевое слово

L

label, v

помечать, отмечать

linker, n

компоновщик.

local variable

локальная переменная

location, n

ячейка памяти

lookup table

таблица поиска, таблица преобразования, справочная таблица, таблица соответствия

loop, n

цикл, петля

loop counter

счётчик цикла

loop unrolling

развертывание цикла, превращение цикла в линейную последовательность команд (может производиться для ускорения исполнения программы, поскольку сокращает каждый цикл на несколько команд)

M

machine code

машинный код, программа на машинном языке

measure, v

измерять

memory, n

память

memory access

выборка из памяти (запоминающего устройства); обращение к памяти (запоминающему устройству)

mnemonic. n

мнемосхема

modify, v

модифицировать, изменять

modular program

модульная программа

multidimensional array

многомерная матрица, многомерный массив

multi-module programs

многомодульные программы

multiple process

многократный процесс

multiplication

умножение

N

non-negative

неотрицательный

O

obvious, a

очевидный

odd, a

нечетный, добавочный.

odd position

нечетная позиция

one's complement , (n)

(поразрядное) дополнение до единицы; обратный код (числа) ( в двоичной системе );

opcode, n

код операции

operand, n

операнд, компонента операции

operator, n

оператор

original value

первоначальное значение

overflow, n

переполнение, избыток

P

parameter, n

параметр

perform, v

выполнять, совершать

pointer, n

указатель

portability, n

портативность

porting , n

перенесение

power, n

степень

precision

точность

precompute, v

предварительно вычислять

prefix, n

префикс

prefix instruction

команда  префикса

printf function

функция printf

processor, n

процессор

provide, v

обеспечивать, предусматривать

purpose, n

цель

push, v

помещать

Q

quotient, n

частное, отношение

R

ramifications, n

разветвления

recast, (v)

рассматривать;

recursion

рекурсия

recursively, adv

рекурсивно

reentrant, n

повторно используемая (программа)

reentrant code

повторно вводимый код

reference, n

ссылка

register

регистр

register-based calling convention  

соглашение о регистровых вызовах

remainder of a division

остаток от деления

represent, (v)

быть изображением, представлять;

representation, n

представление

require, v

требовать, нуждаться

reserved, p.p.

зарезервированный

restriction, n

ограничение

return, v

возвращать

reverse, (a)

перевернутый, обратный, оборотный, инвертированный;

rotate shift

обратный сдвиг

rowwise representation

предстваление в виде строк

rounding up

округление в большую сторону

routine, n

стандартная программа

S

shared library

совместно используемая библиотека, библиотека коллективного доступа

shift, v

перемещать, перестанавливать

shift instructions

инструкции сдвига

sign extension, (n)

расширение знака;

sign flag

флаг знака (+ или -)

signed integer, (n)

целое число со знаком;

signed magnitude, (n)

величина со знаком;

signed magnitude representation

представление величины со знаком

significand, n

мантисса (мантисса числа)

significant, a

существенный, значимый

simplify, v

упрощать

single precision

число одинарной точности

smart compiler

компилятор с развитой логикой

snippet of code

фрагмент, отрывок, кусок кода

source file

исходный файл

specify, v  

задавать, уточнять, определять

stack, n

стек

startup code

начальный код

statement. n

выражение, оператор

store, v

хранить

straightforward binary,

прямой код, прямое представление двоичного числа;

string, n

строка

string instruction  

команда работы со строками

subroutine, n

подпрограмма

subprogram, n

подпрограмма

subprogram call

вызов подпрограммы

subtract, (v)

вычитать;

succinctly, adv

кратко, сжато, локонично

T

technique, n

техника, технические приёмы, методика

tedious, a

утомительный

terminate, v

прекращать. прерывать

truth table

таблица истинности

two’s complement, (n)

двойное дополнение;

U

unary operation

одноместная операция, унарная операция, операция над одним операндом

underline

подчеркивание

unit, n

единица, часть, блок

universal convention

универсальное соглашение, договоренность

unnormalized form

ненормализованная форма

unsigned, a

беззнаковое

unsigned integer, (n)

целое число без знака;

V

variable, n

переменная (величина)

variable storage

переменное запоминающее устройство

vary, v

разниться; отличаться, различаться, расходиться

Y

yield, (v)

получать, давать (в результате какой-либо операции);

CONTENTS

[1]
Unit 1

[2] Text 1 Number Systems

[3] Text 2 Computer Organization

[4] Unit 2

[5] Text 4 Basic instructions

[6] Text 5 Directives

[7] Unit 3

[8] Text 1  Creating a Program

[9] Text 2 First program

[10] Text 3 Compiler dependencies

[11] Text 4 Assembling the code

[12] Text 5 Linking the object files

[13] Unit 4

[14] Text 1 Working with Integers

[15] Text 2 Signed magnitude

[16] Text 3 One’s complement

[17] Text 4 Two’s complement

[18] Text 5 Sign extension

[19] Unit 5

[20] Text 1 Control Structures

[21] Text 2 Comparisons

[22] Text 3 Branch instructions

[23] Text 4 The loop instructions

[24] Text 5 Translating Standard Control Structures

[25] Text 6 Finding Prime Numbers

[26] Unit 6

Учебное издание

английский язык

Практикум

для развития навыков технического перевода,

чтения и устной речи

по теме

«ASSEMBLER LANGUAGE»

для студентов специальности

1-45 01 03 – Сети телекоммуникаций

специализации

1-45 01 03 04 – Программное обеспечение сетей телекоммуникаций

Составитель 

Игнатьева Евгения Матвеевна

Редактор Е. Б. Левенкова

Компьютерная верстка Н.И. Марковская,

Т. В. Белайшис

План 2008/2009, поз.

Подписано в печать 2009 Формат 60х84/16.

Бумага офсетная. Гарнитура «Times».

Печать цифровая.

Усл. печ. л.. Уч.-изд. л.

Тираж 50 экз. Заказ

Издатель и полиграфическое исполнение:

учреждение образования

«Высший государственный колледж связи»

ЛИ № 02330/ 0131902 от 03.01.2007

Ул. Ф. Скорины, 8/2, 220114, Минск.




1. Способы коррекции неблагоприятных функциональных состояний субъекта труда. Методы диагностики функциональных состояний субъекта труда
2. Храмовое строительство на Руси в XVI-XVII вв
3. Дипломатия России Петровских времен
4. Применение методов сетевого планирования при составлении плана закупок материально-технических ресурсов.html
5. Доклады- 1 Этапы развития науки и техники
6. по теме Заболевания щитовидной железы для блока Детская эндокринология для 4 курса ОМ Кафедра эндокри
7. Время его герой и антигерой
8. Контрольная работа Вариант По дисциплинемикроэкономика Направления 0
9. радиусвектор проведенный из точки в точку приложения силы
10. Туризм в природоохоронних територіях
11. Вариант 1 1 Выберите при каком заболевании происходит воспаление целой доли легкого а бронхоэктатическо
12. Nd I~ve got roomful of witnesses.
13. ПРАВО ВЛАСНОСТІ НА ЗЕМЛЮ Особливості права власності на землю полягають у тому що згідно зі ст
14. Бессоница
15. 10 способов манипулирования с помощью средств массовой информации
16. БАЛТИКА 2КОМФОРТ 3
17. руб. п
18. це сукупність сталих індивідуальних особливостей особистості які виявляються в її діяльності і поведінці
19. по теме- Оценка эффективности деятельности врачатерапевта участкового
20. ТЕМА СТАТИСТИЧНОЇ ДІАГНОСТИКИ СТАНУ ВИРОБІВ ІЗ КОМПОЗИЦІЙНИХ МАТЕРІАЛІВ Спеціаль