MP Lab Manual
MP Lab Manual
MP Lab Manual
AIM: : Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from user and store them in
an array and display the accepted numbers.
OBJECTIVES:
ENVIRONMENT:
Operating System: 64-bit Open source Linux or its derivative.
Programming Tools: Preferably using Linux equivalent or MASM/TASM/NASM/FASM.
Text Editor: geditor
THEORY:
Each personal computer has a microprocessor that manages the computer's arithmetical, logical and
control activities. Each family of processors has its own set of instructions for handling various
operations like getting input from keyboard, displaying information on screen and performing various
other jobs. These set of instructions are called 'machine language instruction'. Processor understands
only machine language instructions which are strings of 1s and 0s. However machine language is too
obscure and complex for using in software development. So the low level assembly language is
designed for a specific family of processors that represents various instructions in symbolic code
and a more understandable form. Assembly language is a low-level programming language for a
computer, or other programmable device specific to particular computer architecture in contrast to most
high-level programming languages, which are generally portable across multiple systems. Assembly
language is converted into executable machine code by a utility program referred to as an assembler
like NASM, MASM etc.
If you select "Development Tools" while installed Linux, you may NASM installed along with the
Linux operating system and you do not need to download and install it separately. For checking
whether you already have NASM installed, take the following steps:
Open a Linux terminal.
Type whereis nasm and press ENTER.
If it is already installed then a line like, nasm: /usr/bin/nasm appears. Otherwise, you will see
justnasm:, then you need to install NASM.
The order in which these sections fall in your program really isn’t important, but by convention the
.data section comes first, followed by the .bss section, and then the .text section.
The actual machine instructions that make up your program go into the .text section. Ordinarily, no data
items are defined in .text. The .text section contains symbols called labels that identify locations in the
program code for jumps and calls, but beyond your instruction mnemonics, that’s about it.
All global labels must be declared in the .text section, or the labels cannot be ‘‘seen’’ outside your
program by the Linux linker or the Linux loader. Let’s look at the labels issue a little more closely.
Labels
A label is a sort of bookmark, describing a place in the program code and giving it a name that’s easier
to remember than a naked memory address. Labels are used to indicate the places where jump
instructions should jump to, and they give names to callable assembly language procedures.
Here are the most important things to know about labels:
Labels must begin with a letter, or else with an underscore, period, or question mark. These last
three have special meanings to the assembler, so don’t use them until you know how NASM
interprets them.
Labels must be followed by a colon when they are defined. This is basically what tells NASM
that the identifier being defined is a label. NASM will punt if no colon is there and will not flag
an error, but the colon nails it, and prevents a mistyped instruction mnemonic from being
mistaken for a label. Use the colon!
Labels are case sensitive. So yikes:, Yikes:, and YIKES: are three completely different labels.
INPUT: ARRAY
OUTPUT: ARRAY
STEP 1: Start.
STEP 2: Initialize the data segment.
Counter.
STEP 9: Jump to step 5 until counter value is not zero. STEP 9: Display msg2.
STEP 10: Initialize counter to 05 and rbx as 00 TEP 11: Display element
of array.
Counter.
STEP 15: Jump to step 11 until counter value is not zero. STEP 16: Stop
FLOWCHART:
PROGRAM:
section .data
msg1 db 10,13,"Enter 5 64 bit numbers"
len1 equ $-msg1
msg2 db 10,13,"Entered 5 64 bit numbers"
len2 equ $-msg2
section .bss
array resd 200
counter resb 1
section .text
global _start
_start:
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall
;accept
mov byte[counter],05
mov rbx,00
loop1:
mov rax,0 ; 0 for read
mov rdi,0 ; 0 for keyboard
mov rsi, array ;move pointer to start of
array add rsi,rbx
mov rdx,17
syscall
add rbx,17 ;to move counter
dec byte[counter]
JNZ loop1
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg2
mov Rdx,len2
syscall
;display
mov byte[counter],05
mov rbx,00
loop2:
mov rax,1 ;1 for write
mov rdi, 1 ;1 for
monitor mov rsi, array
add rsi,rbx
mov rdx,17 ;16 bit +1 for enter
syscall
add rbx,17
dec byte[counter]
JNZ loop2
;exit system call
mov rax ,60
mov rdi,0
syscall
;output
:~$ cd ~/Desktop
:~/Desktop$ nasm -f elf64 ass1.asm
:~/Desktop$ ld -o ass1 ass1.o
~/Desktop$ ./ass1
AIM: Write an X86/64 ALP to accept a string and to display its length.
OBJECTIVES:
ENVIRONMENT:
Operating System: 64-bit Open source Linux or its derivative.
Programming Tools: Preferably using Linux equivalent or MASM/TASM/NASM/FASM.
Text Editor: geditor
THEORY:
MACRO:
Procedures or subroutines are very important in assembly language, as the assembly language
programs tend to be large in size. Procedures are identified by a name. Following this name, the body
of the procedure is described which performs a well-defined job. End of the procedure is indicated by a
return statement.
Syntax
proc_name:
procedure body
...
ret
The procedure is called from another function by using the CALL instruction. The CALL instruction should have
the name of the called procedure as an argument as shown below −
CALL proc_name
The called procedure returns the control to the calling procedure by using the RET instruction.
ALGORITHM:
INPUT: String
STEP 1: Start.
STEP 4: accept string from user and store it in Rsi Register (Its length gets stored in Rax register by
default).
STEP 5: Display the result using “display” procedure. Load length of string in data register.
09h
STEP 15: Loop the statement till counter value becomes zero
STEP 16: Call macro dispmsg and pass result variable and length to it. It will print length of string.
mov rax,0
mov rdi,0
mov rsi,str1
mov rdx,200
syscall
call display
%macro dispmsg 2
mov Rax,1
mov Rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
display:
mov rbx,rax ; store no in rbx
mov rdi,result ;point rdi to result variable
mov cx,16 ;load count of rotation in cl
up1:
rol rbx,04 ;rotate no of left by four bits
mov al,bl ; move lower byte in al
and al,0fh ;get only LSB
cmp al,09h ;compare with 39h
jg add_37 ;if greater than 39h skip add 37
add al,30h
jmp skip ;else add 30
add_37:
add al,37h
skip:
mov [rdi],al ;store ascii code in result variable
inc rdi ; point to next byte
dec cx ; decrement counter
jnz up1 ; if not zero jump to repeat
dispmsg result,16 ;call to macro
ret
EXP NO: 03
AIM: Write an X86/64 ALP to find the largest of given Byte/Word/Dword/64-bit numbers
OBJECTIVES:
ENVIRONMENT:
Datatype in 80386:
Datatypes of 80386:
The 80386 supports the following data types they are
Bit
Bit Field: A group of at the most 32 bits (4bytes)
Bit String: A string of contiguous bits of maximum 4Gbytes in length.
Signed Byte: Signed byte data
Unsigned Byte: Unsigned byte data.
Integer word: Signed 16-bit data.
Long Integer: 32-bit signed data represented in 2's complement form.
Unsigned Integer Word: Unsigned 16-bit data
Unsigned Long Integer: Unsigned 32-bit data
Signed Quad Word: A signed 64-bit data or four word data.
Unsigned Quad Word: An unsigned 64-bit data.
Offset: 16/32-bit displacement that points a memory location using any of the addressing modes.
Pointer: This consists of a pair of 16-bit selector and 16/32-bit offset.
Character: An ASCII equivalent to any of the alphanumeric or control characters.
Strings: These are the sequences of bytes, words or double words. A string may contain minimum one byte and maximum
4 Gigabytes.
BCD: Decimal digits from 0-9 represented by unpacked bytes.
Packed BCD: This represents two packed BCD digits using a byte, i.e. from 00 to 99.
Registers in 80386:
General Purpose Register: EAX, EBX, ECX, EDX
Pointer register: ESP, EBP
Index register: ESI, EDI
Segment Register: CS, FS, DS, GS, ES, SS
Eflags register: EFLAGS
System Address/Memory management Registers : GDTR, LDTR, IDTR
Control Register: Cr0, Cr1, Cr2, Cr3
Debug Register : DR0, DR,1 DR2, DR3, DR4, DR5, DR6, DR7
Test Register: TR0, TR,1 TR2, TR3, TR4, TR5, TR6, TR7
EAX AX AH,AL
EBX BX BH,BL
ECX CX CH,CL
EDX DX DH,DL
EBP BP
EDI DI
ESI SI
ESP
AIM: Write a switch case driven X86/64 ALP to perform 64 -bit hexadecimal arithmetic operations (+,-
,*, /) using suitable macros. Define procedure for each operation.
OBJECTIVES:
To understand assembly language programming instruction set.
To understand different assembler directives with example.
To apply instruction set for implementing X86/64 bit assembly language programs
ENVIRONMENT:
THEORY:
1. 80386
Architecture of 80386
• Central processing unit is further divided into Execution unit and Instruction unit
• Execution unit has 8 General purpose and 8 Special purpose registers which are either used
for handling data or calculating offset addresses.
The Instruction unit decodes the opcode bytes received from the 16-byte instruction code queue and arranges
them in a 3- instruction decoded instruction queue.
• After decoding them pass it to the control section for deriving the necessary control signals. The barrel
shifter increases the speed of all shift and rotate operations.
• The multiply / divide logic implements the bit-shift-rotate algorithms to complete the operations in
minimum time.
• Even 32- bit multiplications can be executed within one microsecond by the multiply / divide logic.
The Memory management unit consists of a Segmentation unit and a Paging unit.
• Segmentation unit allows the use of two address components, viz. segment and offset for relocability
and sharing of code and data.
• The Paging unit organizes the physical memory in terms of pages of 4kbytes size each.
• Paging unit works under the control of the segmentation unit, i.e. each segment is further divided into
pages. The virtual memory is also organizes in terms of segments and pages by the memory
management unit. The Segmentation unit provides a 4 level protection mechanism for protecting and
isolating the system code and data from those of the application program.
• The control and attribute PLA checks the privileges at the page level. Each of the pages maintains
the paging information of the task. The limit and attribute PLA checks segment limits and attributes at
segment level to avoid invalid accesses to code and data in the memory segments. The Bus control
unit has a prioritizer to resolve the priority of the various bus requests.
• This controls the access of the bus. The address driver drives the bus enable and address signal A0
–A31.
The pipeline and dynamic bus sizing unit handle the related control signals.
• The data buffers interface the internal data bus with the system bus.
Processor Registers
There are sixteen registers that are of use to general purpose programmers. (There are several other
registers for system level programming that are not discussed in this guide.)
General Registers
There are 8 general purpose, 32-bit registers in the 80386. They are EAX, EBX, ECX, EDX, EBP, ESP,
ESI, and EDI. Each register can hold a doubleword containing any of the data types listed above.
A backwards compatible feature is built into the 80386. The lower word of each register can be
addressed as a separate unit. This is useful for handling 16-bit data items and for compatibility with
older 8086 and 80286 programs. The registers are named AX, BX, CX, DX, BP, SP, SI and DI. Note,
the upper word of each register cannot be addressed separately.
Furthermore, each byte of the four 16-bit registers AX, BX, CX, and DX can be separately addressed.
The high bytes are named AH, BH, CH and DH. The lower bytes are named AL, BL, CL and DL.
All of the general purpose registers are available for addressing calculations and for the results of most
calculations. However, a number of functions expect their data to be in specific registers. This allows
for more compact and efficient instructions.
Segment Registers
There are six segment registers, CS, DS, SS, ES, FS, and GS. They are used to identify the current six
segments in use by a program. The CS registers contains the address of the currently running code
segment. The DS register contains the address of the currently accessible data segment. The SS register
contains the address of the current stack segment. The ES, FS, and GS registers contains additional
segments as required by the program.
The flat memory model used by GAS, has only one segment and therefore programmer's don't normally
need too worry about the segment registers. They are usually loaded up with selectors for descriptors
that contain the entire 32-bit linear address space. Once loaded, there is no need to change them, and the
32-bit pointers can address the entire program. You don't need to worry about this initialization since
defaults are selected when your program is loaded. (Selectors and descriptors are part of protected mode
programming.)
While GAS does not use the segmentation model of the 80386, it has it's own segmentation model using
sections. As a minimum there are 3 sections, the text section containing code, the data section and the
bss section, which contains initialization data. You can also create your own sections. All sections are
contained within the same segment. Sections with the same name are combined together during linking.
ALGORITHM:
FLOWCHART:
PROGRAM:
section .data
menumsg db 10,'****** Menu ******',
db 10,'1: Addition'
db 10,'2: Subtraction'
db 10,'3: Multiplication'
db 10,'4: Division'
db 10,10,'Enter your choice:: '
nummsg db 10
result dq 0
resmsg db 10,'Result is:'
resmsg_len equ $-resmsg
case1:cmp byte[choice],'1'
jne case2
call add_proc
jmp up
case2:
cmp byte[choice],'2'
jne case3
call sub_proc
jmp up
case3:
cmp byte[choice],'3'
jne case4
call mul_proc
jmp up
case4:
cmp byte[choice],'4'
jne caseinv
call div_proc
jmp up
caseinv:
scall 1,1, wrchmsg,wrchmsg_len
exit:
mov eax,01
mov ebx,0
int 80h
add_proc:
mov rax,[no1]
adc rax,[no2]
mov [result],rax
scall 1,1,resmsg,resmsg_len
mov rbx,[result]
call disp64num
scall 1,1,nummsg,1
ret
sub_proc:
mov rax,[no1]
subb rax,[no2]
mov [result],rax
scall 1,1,resmsg,resmsg_len
mov rbx,[result]
call disp64num
scall 1,1,nummsg,1
ret
mul_proc:
scall 1,1,mulmsg,mulmsg_len
mov rax,[no1]
mov rbx,[no2]
mul rbx
mov [resh],rdx
mov [resl],rax
scall 1,1, resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
scall 1,1,nwmsg,1
ret
div_proc:
scall 1,1,divmsg,divmsg_len
mov rax,[no1]
mov rdx,0
mov rbx,[no2]
div rbx
mov [resh],rdx ;Remainder
mov [resl],rax ;Quotient
scall 1,1, rmsg,rmsg_len
mov rbx,[resh]
call disp64num
scall 1,1, qmsg,qmsg_len
mov rbx,[resl]
call disp64num
scall 1,1, nwmsg,1
ret
disp64num:
mov ecx,16
mov edi,dispbuff
dup1:
rol rbx,4
mov al,bl
and al,0fh
cmp al,09
jbe dskip
add al,07h
dskip: add al,30h
mov [edi],al
inc edi
loop dup1
scall 1,1,dispbuff,16
ret
AIM: Write an X86/64 ALP to count number of positive and negative numbers from the array.
OBJECTIVES:
To understand assembly language programming instruction set.
To understand different assembler directives with example.
To apply instruction set for implementing X86/64 bit assembly language programs
ENVIRONMENT:
THEORY:
Mathematical numbers are generally made up of a sign and a value (magnitude) in which the sign
indicates whether the number is positive, ( + ) or negative, ( – ) with the value indicating the size of the
number, for example 23, +156 or -274. Presenting numbers is this fashion is called “sign-magnitude”
representation since the left most digit can be used to indicate the sign and the remaining digits the
magnitude or value of the number.
Sign-magnitude notation is the simplest and one of the most common methods of representing positive
and negative numbers either side of zero, (0). Thus negative numbers are obtained simply by changing
the sign of the corresponding positive number as each positive or unsigned number will have a signed
opposite, for example, +2 and -2, +10 and -10, etc.
But how do we represent signed binary numbers if all we have is a bunch of one’s and zero’s. We
know that binary digits, or bits only have two values, either a “1” or a “0” and conveniently for us, a
sign also has only two values, being a “+” or a “–“.
Then we can use a single bit to identify the sign of a signed binary number as being positive or negative
in value. So to represent a positive binary number (+n) and a negative (-n) binary number, we can use
them with the addition of a sign.
For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is “0”,
this means the number is positive in value. If the sign bit is “1”, then the number is negative in value.
The remaining bits in the number are used to represent the magnitude of the binary number in the
usual unsigned binary number format way.
Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values by
dividing the “n” total bits into two parts: 1 bit for the sign and n–1 bits for the value which is a pure
binary number. For example, the decimal number 53 can be expressed as an 8-bit signed binary
number as follows.
ALGORITHM:
STEP 1: Initialize index register with the offset of array of signed numbers
STEP 2: Initialize ECX with array element count
STEP 3: Initialize positive number count and negative number count to
zero STEP 4: Perform MSB test of array element
STEP 5: If set jump to step 7
STEP 6: Else Increment positive number count and jump to step 8
STEP 7: Increment negative number count and continue
STEP 8: Point index register to the next element
STEP 9: Decrement the array element count from ECX, if not zero jump to step 4, else continue
STEP 10: Display Positive number message and then display positive number count
STEP 11: Display Negative number message and then display negative number count
STEP 12: EXIT
FLOWCHART:
PROGRAM:
;Write an ALP to count no. of positive and negative numbers from the array.
section .data
nwline db 10
array dw 8505h,90ffh,87h,88h,8a9fh,0adh,02h,8507h
arrcnt equ 8
pcnt db 0
ncnt db 0
section .bss
dispbuff resb 2
up1: ;label
bt word[esi],15
;bit test the array number (15th byte) pointed by esi.
;It sets the carray flag as the bit tested
jnc pnxt ;jump if no carry to label pskip
inc byte[ncnt] ;if the 15th bit is 1 it signifies it is a ;negative no and so we ;use this command to
increment ncnt counter.
jmp pskip ;unconditional jump to label skip
inc esi
loop up1 ;loop it ends as soon as the array end “count” or
disp8num:
mov ecx,2 ;move 2 in ecx ;Number digits to display
mov edi,dispbuff ;Temp buffer
dskip:
add al,30h ;Add 30h to accumulator
mov [edi],al ;Store ASCII code in temp buff (move contents ;of accumulator to the location
pointed by edi)
inc edi
;Increment destination index i.e. pointer to ;next location in temp
buff loop dup1 ;repeat till ecx becomes zero
OUTPUT:
;[root@comppl2022 ~]# nasm -f elf64 Exp5.asm
;[root@comppl2022 ~]# ld -o Exp6 Exp5.o
;[root@comppl2022 ~]# ./Exp5
;Welcome to count +ve and -ve numbers in an array
;Count of +ve numbers::05
;Count of -ve numbers::03
;[root@comppl2022 ~]
EXP NO: 06
AIM: Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD number and 5- digit
BCD number into its equivalent HEX number. Make your program user friendly to accept the choice
from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT. Display proper strings to prompt the user
while accepting the input and displaying the
result. (Wherever necessary, use 64-bit registers).
OBJECTIVES:
ENVIRONMENT:
THEORY:
The “Hexadecimal” or simply “Hex” numbering system uses the Base of 16 system and are a popular
choice for representing long binary values because their format is quite compact and much easier to
understand compared to the long binary strings of 1’s and 0’s.
Being a Base-16 system, the hexadecimal numbering system therefore uses 16 (sixteen) different digits
with a combination of numbers from 0 to 9 and A to F.
Hexadecimal Numbers is a more complex system than using just binary or decimal and is mainly used
when dealing with computers and memory address locations.
Binary coded decimal (BCD) is a system of writing numerals that assigns a four-digit binary code to
each digit 0 through 9 in a decimal (base-10) numeral. The four-bit BCD code for any particular single
base-10 digit is its representation in binary notation, as follows:
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
Numbers larger than 9, having two or more digits in the decimal system, are expressed digit by
digit. For example, the BCD rendition of the base-10 number 1895 is
0001 1000 1001 0101
The binary equivalents of 1, 8, 9, and 5, always in a four-digit format, go from left to right.
The BCD representation of a number is not the same, in general, as its simple binary representation.
In binary form, for example, the decimal quantity 1895 appears as
11101100111
BCD Number
Decimal Number 4-bit Binary Number Hexadecimal Number
0 0000
0 0000 0000
1 0001
1 0000 0001
2 0010
2 0000 0010
3 0011
3 0000 0011
4 0100
4 0000 0100
5 0101
5 0000 0101
6 0110
6 0000 0110
7 0111
7 0000 0111
8 1000
8 0000 1000
9 1001
9 0000 1001
10 1010
A 0001 0000
11 1011
B 0001 0001
12 1100
C 0001 0010
HEX to BCD
Divide FFFF by 10 this FFFF is as decimal 65535 so
Division
65535 / 10 Quotient = 6553 Reminder = 5
6553 / 10 Quotient = 655 Reminder = 3
655 / 10 Quotient = 65 Reminder = 5
65 / 10 Quotient = 6 Reminder = 5
6 / 10 Quotient = 0 Reminder = 6
and we are pushing Reminder on stack and then printing it in reverse order.
BCD to HEX
1 LOOP : DL = 06 ; RAX = RAX * RBX = 0 ; RAX = RAX + RDX = 06
2 LOOP : DL = 05 ; 60 = 06 * 10 ; 65 = 60 + 5
3 LOOP : DL = 05 ; 650 = 60 * 10 ; 655 = 650 + 5
4 LOOP : DL = 03 ; 6550 = 655 * 10 ; 6553 = 6550 + 3
5 LOOP : DL = 06 ; 65530 = 6553 * 10 ; 65535 = 65530 + 5
Hence final result is in RAX = 65535 which is 1111 1111 1111 1111 and when we
print this it is represented as FFFF.
ALGORITHM:
STEP 1: Start
STEP 2: Initialize data section.
STEP 3: Using Macro display the Menu for HEX to BCD, BCD to HEX and exit. Accept the
choice from user.
STEP 4: If choice = 1, call procedure for HEX to BCD
conversion. STEP 5: If choice = 2, call procedure for BCD to
HEX conversion. STEP 6: If choice = 3, terminate the program.
user.
STEP 8: Make count in RCX register 0.
STEP 9: Move accepted hex number in BX to AX.
STEP 10: Move base of Decimal number that is 10 in
BX. STEP 11: Move zero in DX.
STEP 12: Divide accepted hex number by 10. Remainder will return in DX.
STEP 13: Push remainder in DX on to stack.
STEP 14: Increment RCX counter.
STEP 15: Check whether AX contents are zero.
STEP 16: If it is not zero then go to step 5.
STEP 17: If AX contents are zero then pop remainders in stack in RDX.
STEP 18: Add 30 to get the BCD number.
STEP 19: Increment RDI for next digit and go to step 11.
FLOWCHART:
PROGRAM
section .data
msg1 db 10,10,'###### Menu for Code Conversion ######' db 10,'1: Hex to BCD'
db 10,'2: BCD to Hex' db 10,'3: Exit'
db 10,10,'Enter Choice:' msg1length equ $-msg1
%macro disp 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
menu:
disp msg1,msg1length
accept arr,2 ; choice either 1,2,3 + enter
jmp menu
exit:
mov rax,60
mov rbx,0
syscall
hex2bcd_proc:
disp msg2,msg2length
accept arr,5 ; 4 digits + enter
call conversion
mov rcx,0
mov ax,bx
mov bx,10 ;Base of Decimal No. system
l33: mov dx,0
div bx ; Divide the no by 10
push rdx ; Push the remainder on stack
inc rcx
inc byte[cnt]
cmp ax,0
jne l33
disp msg3,msg3length
l44: pop rdx ; pop the last pushed remainder from
stack add dl,30h ; convert it to ascii
mov [ans],dl
disp ans,1
dec byte[cnt]
jnz l44
ret
bcd2hex_proc:
disp msg4,msg4length
accept arr,6 ; 5 digits + 1 for enter
disp msg6,msg6length
mov rsi,arr
mov rcx,05
mov rax,0
mov ebx,0ah
conversion:
mov bx,0
mov ecx,04
mov esi,arr
up1:
rol bx,04
mov al,[esi]
cmp al,39h
jbe l22
sub al,07h
l22: sub al,30h
add bl,al
inc esi
loop up1
ret
; the below procedure is to display 32 bit result in ebx why 32 bit & not 16 ;bit; because 5 digit bcd no ranges
between 00000 to 99999 & for ;65535 ans ;is FFFF
; i.e if u enter the no between 00000-65535 u are getting the answer between
;0000-FFFF, but u enter i/p as 99999 urans is greater than 16 bit which is ;not; fitted in 16 bit register so 32 bit
register is taken frresult
disp32_num:
mov rdi,dispbuff
mov rcx,08 ; since no is 32 bit,no of digits 8
l77:
rol ebx,4
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jbe l66
add dl,07h
l66:
mov [rdi],dl
inc rdi
dec rcx
jnz l77
disp dispbuff+3,5 ;Dispays only lower 5 digits as upper three are '0'
ret
;OUTPUT OF PROGRAM
;Enter Choice:1
;Enter 4 digit hex number::FFFF
;BCD Equivalent::65535
;Enter Choice:1
;BCD Equivalent::255
;###### Menu for Code Conversion ######
;1: Hex to BCD
;2: BCD to Hex
;3: Exit
;Enter Choice:1
;BCD Equivalent::15
;Enter Choice:2
;Hex Equivalent::0FFFF
;Enter Choice:2
;Enter 5 digit BCD number::00255
;Hex Equivalent::000FF
AIM: Write X86/64 ALP to detect protected mode and display the values of GDTR, LDTR, IDTR, TR
and MSW Registers also identify CPU type using CPUID instruction.
OBJECTIVES:
ENVIRONMENT:
The DOS Protected Mode Interface (DPMI) allows DOS program to access the advance features of
80286,386,486 based PC’s in a well-behaved hardware-independent fashion that does not compromise
system protection, DPMI function are defined to manage the local descriptor tables, perform mode
switching, allocates extended memory, allocate DOS memory, Control the interrupt subsystem,
communicate with real mode programs, and read or write certain CPU control registers.
Interrupt Function:-
Int 2FH
AX=1687H
Returns:-
If function successful
AX=0
BX=flags
Bit significance
0 0=32-bit programs are not
supported 1=32-bit programs are
supported
1-15 Not used
Int 2fh is the so-called DOS Multiplex Interrupt, used by many different drivers and resident
utilities,and most of the DPMI functions supported on Int 2FH can be called in either real mode or
protected mode.
6.5. Algorithm
ENVIRONMENT:
THEORY:
Addressing modes:
It is an aspect of the instruction set architecture in most central processing unit (CPU) designs.
The various addressing modes that are defined in a given instruction set architecture define how
machine language instructions in that architecture identify the operand(s) of each instruction.
An addressing mode specifies how to calculate the effective memory address of an operand by
using information held in registers and/or constants contained within a machine instruction or
elsewhere.
1. Data addressing modes
2. Memory addressing modes, and
3. Stack addressing
The data-addressing modes include:-
1. Register
2. Immediate
3. Direct
4. Register indirect
5. Base plus-index
6. Register relative
7. Base relative-plus-index
8. Scaled-index
MOV AX, BX instruction transfers the word contents of the source register (BX) into the destination
register (AX). The source never changes, but the destination usually changes. It is essential to remember
that a MOV instruction always copies the source data and into the destination. The MOV never actually
picks up the data and moves it. Also, note that the flag register remains unaffected by most data transfer
instructions. The source and destination are often called operands.
1. Register Addressing
Register addressing is the most common form of data addressing. The microprocessor contains the
following 8-bit registers used with register addressing: AH, AL, BH, BL, CH, CL, DH, and DL. Also
present are the following 16-bit registers: AX, BX, CX, DX, SP, BP, SI, and DI. In the 80386 and
above, the extended 32-bit registers are EAX, EBX, ECX, EDX, ESP, EBP, EDI, and ESI. With register
addressing, some MOV instructions, and the PUSH and POP instructions, also use the 16 -bit segment
registers (CS, ES, DS, SS, FS, and GS).
It is important for instructions to use registers that are the same size. Never mix an 8 -bit register with a
16-bit register, an 8-bit register with a 32-bit register, or a 16-bit register with 32-bit register because
this is not allowed by the microprocessor and results in an error when assembled. This is even true
when a MOV AX,AL or a MOV EAX,AL instruction may seem to make sense. Of course, the MOV
AX,AL or MOV EAX,AL instruction is not allowed because these registers are of different sizes. Note
that a few instructions, such as SHL DX,CL, are exceptions to this rule. It is also important to note that
none of the MOV instructions affect the flag bits.
It is impossible to show all combinations because there are too many. A segment-to-segment register
MOV instruction is not allowed. Note that the code segment register is not normally changed by a MOV
instruction because the address of the next instruction is found in both IP/EIP and CS. If only CS were
changed, the address of the next instruction would be unpredictable. Therefore, changing the CS register
with a MOV instruction is not allowed.
Operation of the MOV BX,CX instruction. The source register’s contents do not change, but the
destination register’s contents do change. The instruction copies a 1234H from register CX into register
BX. This erases the old contents (76AFH) of register BX, but the contents of CX remain unchanged.
The contents of the destination register or destination memory location change for all instructions
except the CMP and TEST instructions. The MOV BX, CX instruction does not affect the leftmost 16
bits of register EBX.
2. Direct Data Addressing:
Most instructions can use the direct data-addressing mode. In fact, direct data addressing is applied
to many instructions in a typical program. There are two basic forms of direct data addressing:
Direct addressing, which applies to a MOV between a memory location and AL, AX, or EAX, and
Displacement addressing, this applies to almost any instruction in the instruction set. In either case, the
address is formed by adding the displacement to the default data segment address or an alternate
segment address.
Direct Addressing; Direct addressing with a MOV instruction transfers data between a memory
location, located within the data segment, and the AL (8-bit), AX (16-bit), or EAX (32-bit) register. A
MOV instruction using this type of addressing is usually a 3 -byte long instruction. (In the 80386 and
above, a register size prefix may appear before the instruction, causing it to exceed three bytes in
length.)
The MOV AL, DATA instruction, as represented by most assemblers, loads AL from data segment
memory location DATA (1234H). Memory location DATA is a symbolic memory location, while the
1234H is the actual hexadecimal location. With many assemblers, this instruction is represented as a
MOV AL, [1234H]. The [1234H] is an absolute memory location that is not allowed by all assembler
programs. This may need to be formed as MOV AL,DS:[l234Hj with some assemblers, to show that the
address is in the data segment. Figure 3—5 shows how this instruction transfers a copy of the byte-sized
contents of memory location 1234H into AL. The effective address is formed by adding 1234H (the
offset address) to 1000H (the data segment address of I000H) in a system operating in the real mode.
Register indirect addressing allows data to be addressed at any memory location through an offset
address held in any of the following registers: BP, BX, DI, and SI. For example, if register BX contains
a l000H and the MOV AX,[BX] instruction executes, the word contents of data segment offset address I
000H are copied into register AX. If the microprocessor is operated in the real mode and DS = OIOOH,
this instruction addresses a word stored at memory bytes 2000H and 2001H, and transfers it into register
AX (see Figure 3—6). Note that the contents of 2000H are moved into AL and the contents of 2001H
are moved into AH. The [ ] symbols denote indirect addressing in assembly language. In addition to
using the BP, BX, DI, and SI registers to indirectly address memory, the 80386 and above allow register
indirect addressing with any extended register except.
The data segment is used by default with register indirect addressing or any other addressing mode that
uses BX, DI, or SI to address memory. If the BP register addresses memory, the stack segment is used
by default. These settings are considered the default for these four index and base registers. For the
80386 and above, EBP addresses memory in the stack segment by default; FAX, EBX, ECX, EDX,
EDT, and ESI address memory in the data segment by default. When using a 32 -bit register to address
memory in the real mode, the contents of the 32 -bit register must never exceed 0000FFFFH. In the
protected mode, any value can be used in a 32-bit register that is used to indirectly address memory, as
long as it does not access a location outside of the segment, as dictated by the access rights byte. An
example 80386/80486/Pentium II instruction is MOV EAX,[EBX]. This instruction loads FAX with the
double word-sized number stored at the data segment offset address indexed by EBX.
In some cases, indirect addressing requires specifying the size of the data are specified with the special
assembler directive BYTE PTR, WORD PTR, or DWORD PTR. These directives indicate the size of
the memory data addressed by the memory pointer (PTR). For example, the MOV AL,[DI] instruction
is clearly a byte-sized move instruction, but the MOV [DI], 1OH instruction is ambiguous. Does the
MOV [DI],10H instruction address a byte-, word-, or double-word-sized memory location? The
assembler can’t determine the size of the IOH. The instruction MOV BYTE PTR [DI],10H clearly
designates the location addressed by DI as a byte-sized memory location. Likewise, the MOV DWORD
PTR [DI],10H clearly identifies memory location as double word-sized. The BYTE PTR, WORD PTR,
and DWORD PTR directives are used only with instructions that address a memory location through a
pointer or index register with immediate data.
“dispblk_proc” procedure
1. Move “cnt” into rcx register.
2. Mark label “rdisp”.
3. Push rcx into stack.
4. Move memory location pointed by esi into bl.
5. Call “disp8_proc” procedure.
6. Increment esi.
7. Call macro “dispmsg” and display “spacechar” variable.
8. Pop top of stack value into rcx.
9. Loop the lines of code till label “rdisp” till ecx becomes zero.
10. Return from procedure.
“blkxferwo_proc” procedure:
1. Move starting address of “srcblk” into esi.
2. Move starting address of “dstblk” into edi.
3. Move “cnt” variable value into ecx.
4. Mark label “blkup1”.
5. Move memory value pointed by esi into al.
6. Move value in register al into memory location pointed by edi.
7. Increment esi.
8. Increment edi.
9. Loop the statements till “blkup1” till ecx becomes zero..
10. Return from procedure.
“blkxferw_proc” procedure:
1. Move starting address of “srcblk” into esi.
2. Move starting address of “dstblk” into edi.
3. Clear direction flag.
4. Transfer string pointed by esi into string pointed by edi.
5. Return from procedure.
“showblks” procedure:
1. Call macro “dispmsg” and display “srcmsg” string.
2. Move starting address of “srcblk” into esi.
3. Call “dispblk_proc” procedure.
4. Call macro “dispmsg” and dispaly “dstmsg” variable.
5. Move staring address of “dstblk” into esi.
6. Call “dispblk_proc” procedure.
7. Return from procedure.
“disp8_proc” procedure:
1. . Move 02H into ecx. 6. Compare al with 09H.
2. . Jump if below or equal to label “dskip”.
3. .. Add al with 07H and store result in al.
4. . Mark label dskip.
5. . Add 30H into al register..
6. . Move al into memory location pointed by edi.
7. . Increment edi.
8. . Loop the instructions from “dup1” till ecx becomes zero.
9. Call “dispbuff” macro and display “dispbuff” variable.
10. . Return from procedure.
AIM: Write X86/64 ALP to perform overlapped block transfer with string specific instructions
Block containing data can be defined in the data segment.
OBJECTIVES:
ENVIRONMENT:
THEORY:
Addressing modes:
It is an aspect of the instruction set architecture in most central processing unit (CPU) designs.
The various addressing modes that are defined in a given instruction set architecture define how
machine language instructions in that architecture identify the operand(s) of each instruction.
An addressing mode specifies how to calculate the effective memory address of an operand by
using information held in registers and/or constants contained within a machine instruction or
elsewhere.
1. Data addressing modes
2. Memory addressing modes, and
3. Stack addressing
The data-addressing modes include:-
1. Register
2. Immediate
3. Direct
4. Register indirect
5. Base plus-index
6. Register relative
7. Base relative-plus-index
8. Scaled-index
. Base-Plus-Index Addressing:
In the 80386 and above, this type of addressing allows the combination of any two 32-bit extended
registers except ESP. For example, the MOV DL,[EAX+EBX] instruction is an example using EAX (as
the base) plus EBX (as the index). If the EBP register is used, the data are located in the stack segment
instead of in the data segment.
The base relative-plus-index addressing mode is similar to the base-plus-index addressing mode. but it
adds a displacement, besides using a base register and an index register, to form the memory address.
This type of addressing mode often addresses a two-dimensional array of memory data.
7. Scaled-Index Addressing:
Scaled-index addressing is the last type of data-addressing mode discussed. This data-addressing mode
is unique to the 80386 through the Pentium II microprocessors. Scaled-index addressing uses two 32-bit
registers (a base register and an index register) to access the memory. The second register (index) is
multiplied by a scaling factor. The scaling factor can be 1X, 2X, 4X, or 8X. A scaling factor of lX is
implied and need not be included in the assembly language instruction (MOV AL,[EBX+ECX]). A
scaling factor of 2X is used to address word-sized memory arrays, a scaling factor of 4X is used with
doubleword-sized memory arrays, and a scaling factor of 8X is used with quadword-sized memory
anays.
Example: the MOV CX,DX instruction copies the word-sized contents of register DX into register CX.
In the 80386 and above, a doubleword can be transferred from the source register or memory location to
the destination register or memory location.
Example: the MOV ECX,EDX instruction copies the doubleword-sized contents of register EDX into
register ECX.
Immediate addressing:
Transfers the source-immediate byte or word of data into the destination register or memory
location.
Example: the MOV AL,22H instruction copies a byte-sized 22H into register AL. In the 80386 and
above, a doubleword of immediate data can be transferred into a register or memory location.
Example: the MOV EBX, 12345678H instruction copies a double word-sized 12345678H into the 32-
bit wide EBX register.
Direct addressing:
Moves a byte or word between a memory location and a register. The instruction set does not
support a memory-to-memory transfer, except for the MOVS instruction.
Example: the MOV CX,LIST instruction copies the word-sized contents of memory location LIST into
register Coxing the 80386 and above, a double word-sized memory location can also be addressed.
Example: the MOV ESI,LIST instruction copies a 32-bit number, stored in four consecutive bytes of
memory, from location LIST into register ESI.
Transfers a byte or word between a register and a memory location addressed by an index or
base register. The index and base registers are BP, BX, DI, and SI.
Example: the MOV [AX,IBX] instruction copies the word-sized data from the data segment offset
address indexed by BX into register AX. In the 80386 and above, a byte, word, or double-word is
transferred between a register and a memory location addressed by any register: EAX, EBX, ECX,
EDX, EBP. ED, or ESI.
Example: the MOV AL,[ECX] instruction loads AL from the data segment offset address selected by
the contents of ECX.
Base-plus-index addressing:
Transfers a byte or word between a register and the memory location addressed by a base
register (BP or BX) plus an index register (DI or SI). Example: the MOV [BX+DH,CL] instruction
copies the bytesized contents of register CL into the data segment memory location addressed by BX
plus DI. In the 80386 and above, any register EAX, EBX, ECX, EDX, EBP, EDI, or ESI may be
combined to generate the memory address.
Example: the MOV [EAX+EBX],CL instruction copies the byte-sized contents of register CL into the
data segment memory location addressed by EAX plus EBX.
Moves a byte or word between a register and the memory location addressed by an index or base
register plus a displacement.
e.g. MOV AX,[ECX+4] or MOV AX,ARRAY[EBX]. The first instruction loads AX from the data
segment address formed by ECX plus 4. The second instruction loads AX from the data segment
memory location ARRAY plus the contents of EBX.
Transfers a byte or word between a register and the memory location addressed by a base and an
index register plus a displacement. (Example:
Scaled-index addressing:
Is available only in the 80386 through the Pentium Pro microprocessor. The second register of a
pair of registers is modified by the scale factor of 2X, 4X, or 8X to generate the operand memory
address.
LIST OF INTERRRUPTS USED:
FLOWCHART:
EXP NO: 10
AIM: Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use
successive addition and add and shift method. (use of 64 -bit registers is expected).
OBJECTIVES:
ENVIRONMENT:
THEORY:
LIST OF INTERRRUPTS USED:
ALGORITHM:
Consider that one byte is present in the AL register and another byte is present in the BL register. We
have to multiply the byte in AL with the byte in BL.
We will multiply the numbers using add and shift method. In this method, you add number with
itself and rotate the other number each time and shift it by one bit to left alongwith carry. If carry is
present add the two numbers.
Initialize the count to 4 as we are scanning for 4 digits. Decrement counter each time the bits are added.
The result is stored in AX. Display the result.
Step I :
AX =11
+ 11
22 H
carry. BL = 10 H
0¬0 0 0 1 0 0 0 0
CY
BL = 0 0 0 1 0 0 0
00
CY
20
Step II : Now decrement counter count = 3.
Check for carry, carry is not there so add number with itself.
AX =22
+ 22
44 H
Rotate BL to left,
BL = 0 ¬ 0 1 0 0 0 0 0
0 CY
40
itself AX = 44
+ 44
88 H
Rotate BL to left,
BL = 0 1 0 0 0 0 0 0 0
CY 8 0
Carry is not there.
AX = 88
+ 88
110 H
Rotate BL to left,
BL = 1 0 0 0 0 0 0 0 0
CY 0 0
Carry is there.
Step V : Decrement counter =
0. Carry is present.
4.5 Algorithm
Convert procedure
1. XOR rbx with rbx to initialize it to 0.
2. XOR rcx with rcx to initialize it to 0.
3. XOR rax with rax to initialize it to 0.
4. Move 02H to rcx register.
5. Move the address of “num” variable into rsi.
6. Mark label “up1”.
7. Rotate left bl by 4 bits.
8. Move value at memory location pointed by rsi into al.
9. Compare al with 39H.
10. Jump if greater to “p1”.
11. Subtract 30H from al.
12. Jump to “p2”.
13. Mark label “p1”
14. Subtract 37H from al.
15. Mark label “p2”.
16. Add al into bl.
17. Increment rsi.
18. Loop the statements from label “up1” till ecx becomes zero.
19. Return from procedure.
Display procedure
1. Move 04H into rcx.
2. Move address of “result” variable into rdi.
3. Mark label “dup1”.
4. Rotate left bx register by 4 bits.
5. Move bl into al.
6. And al with 0FH.
7. Compare al with 09H.
8. Compare al with 09H.
9. Jump if greater to label “p3”.
10. Add 30H into al.
11. Jump to label “p4”.
12. Mark label “p3”.
13. Add 37H into al.
14. Mark label “p4”.
15. Move al into memory location pointed by rdi.
16. Increment rdi.
17. Loop the statements starting from label “dup1” till ecx becomes zero.
18. Return from procedure.
Succe_addition procedure
1. Call “dispmsg” macro and display string msg.
2. Call “accept” macro and read “num” variable from keyboard.
3. Call “convert” procedure.
4. Move bl into memory location for “num1” variable.
5. Call “dispmsg” macro and display “msg” string.
6. Call “accept” macro and read “num” variable from keyboard.
7. Call “convert” procedure.
8. XOR rcx with rcx to make it zero.
9. XOR rax with rax to make it zero.
10. Move num1 into rax.
11. Mark label “repet”.
12. Add rax into rcx.
13. Decrement bl register.
14. Jump if not zero to label “repet”.
15. Move rcx into “result” variable.
16. Call “dispmsg” macro and display “res” message.
17. Move “result” variable into rbx register.
18. Call display procedure.
19. Return from procedure.
Add_shift procedure
FLOWCHART:
EXP NO: 11
AIM: Write X86 Assembly Language Program (ALP) to implement following OS commands
i) COPY, ii) TYPE Using file operations. User is supposed to provide command line arguments
OBJECTIVES:
ENVIRONMENT:
THEORY:
The Program Segment Prefix (PSP) is a data structure used in DOS systems to store the state of a program. It
has the following structure:
Offset Size Contents
00-01 2 bytes (code) CP/M exit (always contain INT
20) 02-03 word (2 bytes) Memory size in paragraphs
04 Byte Reserved
05-09 5 bytes (code) Far call to CP/M compatibility code within DOS
0A-0D dword (4 bytes) Terminate address of previous program (old INT
22) 0E-11 Dword Break address of previous program (old INT 23)
12-15 Dword Critical error address of previous program (old INT 24)
16-17 Word Caller's PSP segment (usually command.com -
internal) 18-2B 20 bytes Job File Table (internal)
2C-2D Word Environment segment
2E-31 Dword SS:SP on entry to last INT 21 call
(Internal) 32-33 Word Max open files (Internal - see
below)
34-37 Dword Handle-entries address (Internal - see
below) 38-4F 24 bytes Reserved
50-52 3 bytes (code) Far call to DOS (always contain INT 21 +
RETF) 53-5B 9 bytes Reserved
5C-6B 16 bytes Unopened Standard RFCB 1
6C-7F 20 bytes Unopened Standard FCB 2 (overwritten if FCB 1 is opened)
80 1 byte Number of bytes on command-line
81-FF 127 bytes Command-line (terminated by a 0RDh)
The PSP is most often used to get the command line arguments of a DOS program, for example the
command "foo.exe -a -f" executes foo.exe with the arguments '-a' and '-f'.
The segment address of the PSP is passed in the DS register when the program is executed. It can also
be determined later by using interrupt 21 sub function 62. This interrupt will return the PSP address in
register BX.
Alternatively, in .COM programs, one can address the PSP directly just by using the offsets listed
above. 00h points to the beginning of the PSP, FFh points to the end, etc. For example, the following
code displays the command line arguments:
org 100h
; int 21h subfunction 9 requires '$' to terminate string
xorbx, bx
movbl, [80h]
mov byte [bx + 81h], '$'
; print the
string mov ah,
9 mov dx, 81h
int 21h
; exit
mov ax, 4C00h
int 21h
INT 21H
Function 62H
Obtains the segment address of program segment prefix for currently executing program.
Call with:
AH=4CH.
Returns:
BX=address of PSP.
Function 3CH
Create a file
Given an ASCIIZ pathname, create a new file in the designator default directory on the
designated disk drive. If the specified file already exists, it is truncated to zero length. In either case, the
file opened and a handle is returned that can be used by the program for subsequent access to the file.
Call with:
AH=3CH
attribute (Bit may be combined)
Returns:
If function successful then carry
flag = Clear AX = handle
If function failed
carry flag = set AX=
error code
FUNCTION 0AH
Read line from keyboard and places it in the user-designated buffer. The character are echoed to
display. Read the string of bytes foem standard upto and including an ASCII carriage return (0DH).
Call with:
AH=0AH DS:AX=
Segment : offset of buffer.
Returns:
Nothing.
FUNCTION 40H
Write file or device
Given a valid file handle from a previous open or create operation, a buffer Address, and a
length in byte, transfer data from the buffer into the file and then updates the file pointer.
Call with:
AH=40H
BX=handle
Returns:
If function successful
Carry flag =
clear AX=bytes
If function unsuccessful
Carry flag=set
AX==Error code.
FUNCTION 3FH
Given a valid file handle from a previous open or create operation, a buffer Address, and a
length in byte, transfers data at the current file-pointer position from the file into the buffer and then
updates the file pointer position.
Call with:
AH= 3FH
BX=Handle
Returns:
If function successful
If function unsuccessful
Carry flag=set
AX==Error code.
FUNCTION 09H
Display string
Sends a string of characters to display sends a string of characters to the standard output devices,
output may be redirected.
Call with:
AH=09H
Returns:
Nothing.
FUNCTION 3DH
Open file
Given a ASCIIZ path name opens the specified file in designated or default directory on the
designated or default driver.
Call with:
AH=3DH
AL=Access mode
Bit(s) Significance
0-2 Access mode
ALGORITHM:
FLOWCHART:
EXP NO: 12
AIM: Write X86 ALP to find, a) Number of Blank spaces b) Number of lines c) Occurrence of a
particular character. Accept the data from the text file. The text file has to be accessed during
Program_1 execution and write FAR PROCEDURES in Program_2 for the rest of
the processing. Use of PUBLIC and EXTERN directives is mandatory.
OBJECTIVES:
ENVIRONMENT:
THEORY:
ALGORITHM:
FLOWCHART
EXP NO: 13
AIM: Write x86 ALP to find the factorial of a given integer number on a command line by using
recursion. Explicit stack manipulation is expected in the code.
OBJECTIVES:
ENVIRONMENT:
THEORY:
The factorial number system is a mixed radix numeral system: the i-th digit from the right has base i,
which means that the digit must be strictly less than i, and that (taking into account the bases of the less
significant digits) its value to be multiplied by (i − 1)! (its place value).
he factorial number system is sometimes defined with the 0! Place omitted because it is always zero.
In this article, a factorial number representation will be flagged by a subscript "!", so for instance
341010! stands for 364514031201, whose value is
= 46310.
(Note that the place value is one less than the radix position, which is why these equations begin with
5!.)
General properties of mixed radix number systems also apply to the factorial number system. For
instance, one can convert a number into factorial representation producing digits from right to left, by
repeatedly dividing the number by the place values (1, 2, 3, ...), taking the remainder as digits, and
continuing with the integer quotient, until this quotient becomes 0.
For example, 46310 can be transformed into a factorial representation by these successive divisions:
77 ÷ 4 = 19, remainder 1
19 ÷ 5 = 3, remainder 4
3 ÷ 6 = 0, remainder 3
The process terminates when the quotient reaches zero. Reading the remainders
backward gives 341010!.
In principle, this system may be extended to represent fractional numbers, though rather
than the natural extension of place values (−1)!, (−2)!, etc., which are undefined, the
symmetric choice of radix values n
= 0, 1, 2, 3, 4, etc. after the point may be used instead. Again, the 0 and 1 places may
be omitted as these are always zero. The corresponding place values are therefore
1/1, 1/1, 1/2, 1/6, 1/24... 1/n!, etc.
LIST OF ASSEMBLER
MACROS USED:
LIST OF PROCEDURES
USED: ALGORITHM:
FLOWCHART: