Wednesday 10 February 2016

Demonstration of Paging Tables using Assembly Lanugage

This is a demonstration of the concept of paging using assembly language. Here each page has been declared as an array. And address variable(add) denotes the address which is to be reached. This is assumed to be similar to linear address. This is to be translated to physical address using the concept of paging.



Code

OS:- Linux 64 bit(Fedora)
Assembler:- NASM
Platform:-x86 (32 bit ALP)


;Author:-Abhishek Munagekar
;Program:- To demonstrate paging tables
 section .data
p0 : db "01234567"
p1 : db "abcdefgh"
p2 : db "ABCDEFGH"
p3 : db "zyxwvuts"
add : dd 00010105h   
msg db "Multiplication is"

section .bss
pdir resb 8
pf0 resb 8
pf1 resb 8
temp resb 4

count : resb 01

global _start
section .text
_start:
mov eax, p0   ;initializing frame1
mov esi, pf0
mov [esi], eax
add esi,4
mov eax,p1
mov [esi], eax



mov esi,pf1   ;initializing frame2
mov eax,p2
mov [esi], eax
add esi,4
mov eax,p3
mov [esi],eax

mov esi,pdir   ;initializing directory
mov eax,pf0
mov [esi],eax
add esi,4
mov eax,pf1
mov [esi],eax   ;page tables have been generated

mov eax,[add]
and eax,00FF0000h
rol eax, 16
mov [count],al
mov esi,pdir

sub esi,4   
inc byte[count]
begin:
add esi,4
dec byte[count]
jnz begin

mov eax,dword[esi]
mov [temp],eax
mov esi,[temp]   ;reached frame

mov eax,[add]
and eax,0000FF00h
ror eax,8
mov [count],al
inc byte[count]
sub esi,4

begin2:
add esi,4
dec byte[count]
jnz begin2

mov eax,dword[esi]
mov [temp],eax
mov esi,[temp]   ;reached page

mov eax,[add]
mov [count],al
dec esi
inc byte[count]

begin3:
add esi,1
dec byte[count]
jnz begin3   ;reached the correct value using offset

mov al,byte[esi]  ;move the value to printed in count
mov [count],al

mov eax,4   ;write system call
mov ebx,1
mov ecx,count
mov edx,1
int 80h
mov eax,1   ;exit system call
mov ebx,0
int 80h 
 
 

Output

[SE@localhost ~]$ nasm -f elf page.asm
[SE@localhost ~]$ ld -m elf_i386 -o page page.o
[SE@localhost ~]$ ./page
u
[SE@localhost ~]$

 

No comments:

Post a Comment