Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Experiment 2

Title Find the largest number


Problem statement Write an X86/64 ALP to find the largest of given byte/ Word /
Dword / 64-bit numbers

Theory :
The 80386 supports the 17 data types :
1. Bit: A single bit quantity.
2. Bit Field: A group of up to 32 contiguous bits, which spans a maximum of four bytes.
3. Bit String: A set of contiguous bits, on the 80386 bit strings can be up to 4
gigabits long.
4. signed Byte: A signed 8-bit quantity. ( -128 to +127)
5. Unsigned Byte: An unsigned 8-bit quantity. ( 0 to 255)
6. Signed Integer (Word): A signed 16-bit quantity. ( -32768 to 32767)
7. Unsigned Integer (Word): An unsigned 16-bit quantity ( 0 to 65535)
8. signed Long Integer (Double Word): A signed 32-bit quantity ( -2.147 * 10 9 to 2.147
* 10 9 )
9. Unsigned Long Integer (Double Word): An unsigned 32-bit quantity. (0 to 4.294 * 10 9 )
10. Signed Quad Word: A signed 64-bit quantity.
11. Unsigned Quad Word: An unsigned 64-bit quantity.
12. BCD: a byte contains only one decimal digit (0 to 9)
13. Packed BCD: a byte contains two decimal digits (00 to 99)
14. Offset: A 16- or 32-bit offset which references memory location.
15. Pointer: which consists of a 16-bit segment selector and either a 16- or 32-bit offset.
16. Char: A byte contains ASCII character.
17. String: A contiguous sequence of bytes, words or dwords. A string may contain between
1 byte and 4 Gbytes.
The Intel386 DX has 32 register resources in the following categories:
a. General Purpose Registers : are for Holding data before & after an instruction
execution.

In an instruction ,The size of the operand (byte, word, double word) is conveyed by the
operand itself
➢ EAX means: a 32 bit operand
➢ AX means: a 16 bit operand
➢ AL means: a 8 bit operand.
The size of the source operand and the destination operands must be equal
Index registers ESI & EDI are used for string ( array) operations
Pointer registers ESP & EBP are used in stack segment
b. Segment registers : memory is divided in segments which are used to
store differentparts of program i.e. code ( CS), stack (SS) & data (
DS, ES, FS, GS)

c. Instruction pointer used to hold the address of next instruction.

d. Flags register : control certain operations and indicate some special


status of the resultafter some arithmetic or logical operations

e. Control Registers
The Intel386 DX has three control registers of 32 bits, CR0, CR2 and
CR3, These registers, hold machine status that for all tasks in the system.
f. System Address Registers used to access the tables or segments
when 80386 isoperating in protection model.
g. Debug Registers:
The six debug registers provide on-chip support for debugging.

h. Test Registers: used to control the testing of the Translation Lookaside

Addressing modes
It is the way the operands are specified in an instruction
Control unit in 80386 decides from where to take operand and where to store the
result operand basedon addressing mode used in instruction.
The Intel386 DX provides a total of 11 addressing modes for instructions to specify
operands
1. Register Operand Mode:
• The operand is located in one of the 8-, 16- or 32-bit general registers.
• Eg ADD EAX ,ECX
2. Immediate Operand Mode
in which the operand value is present in the instruction
So when instruction is fetched ,it is fetched along with the
operandNo separate memory access required to fetch data.
Eg ADD EAX, 500E
The value 500E is added to register AX & result is stored in AX

3. Direct Mode:
The operand’s offset is contained as part of the instruction as an 8-, 16- or 32-bit
displacement.
EXAMPLE: ADD EAX, [500E] ; here Offset= 500E
4. Register Indirect Mode:
A BASE register contains the address of the operand.
EXAMPLE: MOV EAX, [EDX] & Suppose EDX contains 2CA7 ; here Offset= 2CA7
5. Based Mode:
A BASE register’s contents is added with a DISPLACEMENT to form the operands offset.
EXAMPLE: MOV ECX, [EAX+24] ; Suppose EAX contains 1000 So offset = 1024
6. Index Mode:
An INDEX register’s contents is added with a DISPLACEMENT to form the operands offset.
EXAMPLE: ADD EAX, [ESI + FD] ; Suppose ESI contains 2000 So offset = 20FD
7. Scaled Index Mode:
An INDEX register’s contents is multiplied by a scaling factor ( which can either 1, 2, 4 or
8)which is added to a DISPLACEMENT to form the operands offset.
EXAMPLE: IMUL EBX, [EDI*2]+7 ; Suppose EDI contains 2000 So offset = 4007
8. Based Index Mode:
The contents of a BASE register is added to the contents of an INDEX register to form the
effective address of an operand.
EXAMPLE: MOV EAX, [ECX] [EBX] ; Suppose ECX =2000 ,EBX =3000 So offset = 5000
9. Based Scaled Index Mode:
The contents of an INDEX register is multiplied by a SCALING factor and the result is added
to the contents of a BASE register to obtain the operands offset.
EXAMPLE: MOV ECX, [EDX*2] [EBP] : suppose EDX = 1000,EBP= 2000 So offset = 4000
10. Based Index Mode with Displacement:
The contents of an INDEX Register and a BASE register’s contents and a DISPLACEMENT
are all summed together to form the operand offset.
EXAMPLE: ADD EDX, [ESI] [EBP+00FFFFF0H] Offset = ESI+ EBP + 00FFFFF0
Possible combinations

11. Based Scaled Index Mode with Displacement:


The contents of an INDEX register are multiplied by a SCALING factor, the result is added to
the contents of a BASE register and a DISPLACEMENT to form the operand’s offset.
EXAMPLE: MOV EAX, [EDI*4] [EBP+80]
So offset = ( EDI*4 ) + EBP + 80

Algorithm
1. Numbers are stored in contiguous memory locations.( array)
2. set a pointer to the start of array
3. set counter equal to total count of numbers
4. set maximum number ( max) as zero.
5. compare max with number pointed by pointer
6. if max is less than number , set max equal to number
7. Increment pointer
8. decrement counter
9. if counter is not zero , go to 5 else got 10
10. display max as maximum number int the array.

Output :

You might also like