- •Content
- •Introduction 5
- •1. Multiplication in assembly language 6
- •2. Troubleshooting 6
- •Introduction
- •1. Multiplication in assembly language
- •1.1 Basic theoretical information
- •Processor Registers
- •Data Registers
- •Pointer Registers
- •Index Registers
- •Control Registers
- •Segment Registers
- •Data Movement Instructions
- •Arithmetic and Logic Instructions
- •1.2 Rules of block diagram representation
- •1.3 Structure of assembly program log.Exe
- •Conclusion
- •References
1.3 Structure of assembly program log.Exe
В моей работе я исследовал алгоритмы работы логических операций на основе полученных данных в течении семестра. Я использовал логические опарторы И(and), ИЛИ(or), Исключающие ИЛИ(xor) и Отрицание(not).
The AND instruction is used for supporting logical expressions by performing bitwise AND operation. The bitwise AND operation returns 1, if the matching bits from both the operands are 1, otherwise it returns 0. For my example I use HEX
5FFF and 2345. In binary system 5FFF is 10111111111111, 2345 is 10001101000101. Then, when I used command AND I get HEX 0234.
10111111111111
10001101000101
10001101000101
That 0234 HEX.
In 13 line i use MOV instruction that is used for moving data from one storage space to another. The MOV instruction takes two operands. First operand is ax and second is 5FFFh. I copy in register AX hex number 5FFF.
Register AX I used for arithmetic operation with my logic operator.
Потом я провожу логическую операцию И. Для ее использования нужно 2 операнда. First operand is ax and second is 2345h. Cохраняю результат копируя значения АХ в переменную REZ.
Переменную REZ я инициализировал в 4 строке. Инициализируется переменная в несколько этапов. Изначально мы выделяем память в сегменте стека. Segmented memory model divides the system memory into groups of independent segments referenced by pointers located in the segment registers. Each segment is used to contain a specific type of data. One segment is used to contain instruction codes, another segment stores the data elements, and a third segment keeps the program stack.
In the light of the above discussion, we can specify various memory segments as −
Data segment − It is represented by .data section and the .bss. The .data section is used to declare the memory region, where data elements are stored for the program. This section cannot be expanded after the data elements are declared, and it remains static throughout the program.
The .bss section is also a static memory section that contains buffers for data to be declared later in the program. This buffer memory is zero-filled.
Code segment − It is represented by .text section. This defines an area in memory that stores the instruction codes. This is also a fixed area.
Stack − This segment contains data values passed to functions and procedures within the program.
В программе я выделил 256 байт командой DB 256 DUP(0)
DB – одно слово(1 байт, 8 бит)
256 – количество байтов
DUP – дубликат
(0)- стартовое значения слова.
В сегменте даты я занимался последним шагом объявление переменной.
rez Dw 1 DUP(0)
rez – название
DW – 2 слова( 2 байта, 16 бит)
Информацию о регистрах можно посмотреть в таблице 4.
В 2 программе я использовал логический оператор ИЛИ.
The OR instruction is used for supporting logical expression by performing bitwise OR operation. The bitwise OR operator returns 1, if the matching bits from either or both operands are one. It returns 0, if both the bits are zero.
Я показал использование инструкции ИЛИ для 1 байта. Для примера были взяты числа 29 HEX и 45 HEX.
Командой Mov поместил в переменную ax число 29HEX.
Дальше использовал логический оператор OR и к первому операнду AX додал второй операнд 45 HEX. В результате получил число 6D HEX.
00101001 01000101 01101101
Number 29 HEX in binary system is 00101001, 45 HEX in binary system is 01000101, 6D in binary system is 01101101, so answer is correct.
Дальше для сохранения результата я использовал команду OFFSET.
mov bx, OFFSET REZ
OFFSET will get the address of a variable which already has it's address allocated. This in turn means, OFFSET could be used to get the address of global variables only. We cannot receive the address of a local variable by using OFFSET as the address of a local variable is not decided during assembly time. BX – base register. Used as a pointer to data (located in segment register DS, when in segmented mode).
Для переменной REZ я выделяю память в ячейку BX.
Mov [bx],ax
На выделеную память копирую значение з регистра AX.
В программе 3 я использовал два оператора XOR и NOT.
The XOR instruction implements the bitwise XOR operation. The XOR operation sets the resultant bit to 1, if and only if the bits from the operands are different. If the bits from the operands are same (both 0 or both 1), the resultant bit is cleared to 0.
The NOT instruction implements the bitwise NOT operation. NOT operation reverses the bits in an operand. The operand could be either in a register or in the memory.
В программе как и для оператора AND я использовал числа 5FFF и 2345. Использовав логический оператор XOR на первый операнд подал число 5FFF HEX , а на второе 2345 HEX. После этого использовал оператор NOT
10111111111111
10001101000101 00110010111010 11001101000101
Registers meanings in table 6
Table 3
Operand 1 |
Operand 2 |
Result of logic operation AND(RESULT) |
5FFF |
2345 |
0234 |
Table 4
Command |
The contents of registers |
|||||||||||||
ax |
bx |
cx |
dx |
cs |
ds |
di |
si |
Flags |
||||||
c |
z |
s |
p |
a |
d |
|||||||||
mox ax,5FFFH |
5FFF |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
mov dx,2345 |
5FFF |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
And ax,dx |
0234 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Mov rez,ax |
0234 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Table 5
Command
|
The contents of registers |
|||||||||||||
ax |
bx |
cx |
dx |
cs |
ds |
di |
si |
Flags |
||||||
c |
z |
s |
p |
a |
d |
|||||||||
mox ax,29H |
0029 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
or ax,45h |
006D |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
mov bx, OFFSET REZ |
006D |
0001 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Mov [bx],ax |
006D |
0001 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Table 6
Command |
The contents of registers |
|||||||||||||
ax |
bx |
cx |
dx |
cs |
ds |
di |
si |
Flags |
||||||
c |
z |
s |
p |
a |
d |
|||||||||
mov ax,0 |
0000 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
mox ax,5FFFH |
5FFF |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Xor ax,2345h |
56D6 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Not ax |
A929 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
Mov rez,ax |
A929 |
0000 |
0000 |
0000 |
48BE |
48BD |
0000 |
0000 |
0 |
0 |
0 |
0 |
0 |
0 |
