Posts

Showing posts with the label world

Hello World in assembly for x86

Code : ;author:md.jamal mohiuddin global _start section .text _start: ;print hello world on the screen mov eax,0x4 ;system call number mov ebx,0x1 ;fd =1 mov ecx,message ;buf points to the message mov edx,11 ;len = 11 int 0x80 ;trap interrupt(software defined) ;exit gracefully mov eax,0x1 ;system call number mov ebx,0x3 ;first argument int 0x80 ;trap interrupt(software defined) section .data message : db "Hello World\n" To execute  nasm -f elf32 -o hello.o hello.asm  ld -o hello hello.o ./hello To check the return type: echo $?

Hello World Device Driver

hello_world.c: #include<linux/module.h> #include<linux/init.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("EMBEDDED GURUJI"); static int hello_init(void) {       printk("Hello World\n");       return 0; } static void hello_exit(void) {      printk("Bye World\n"); } module_init(hello_init); module_exit(hello_exit); Makefile: obj-m := hello_world.o KERNELDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all :     $(MAKE) -C $(KERNEL) M=$(PWD) modules clean:    $(MAKE) -C $(KERNEL) M=$(PWD) clean Now we will understand the code line by line #include<linux/module.h> #include<linux/init.h> These header files contains the definition of the module_init() and module_exit() functions. MODULE_LICENSE("GPL"); MODULE_LICENSE() informs the kernel the license used by the source code,which will affect the functions it can access from  the kernel.MO...