Write ALP to switch from real mode to protected mode and display the values of GDTR, LDTR, IDTR, TR and MSW Registers.

Write ALP to switch from real mode to protected mode and display the values of GDTR, LDTR, IDTR, TR and MSW Registers.

;This program first check the mode of processor(Real or Protected),
;then reads GDTR, LDTR, IDTR, TR & MSW and displays the same.

section .data
rmodemsg db 10,’Processor is in Real Mode’
rmsg_len:equ $-rmodemsg

pmodemsg db 10,’Processor is in Protected Mode’
pmsg_len:equ $-pmodemsg

gdtmsg db 10,’GDT Contents are::’
gmsg_len:equ $-gdtmsg

ldtmsg db 10,’LDT Contents are::’
lmsg_len:equ $-ldtmsg

idtmsg db 10,’IDT Contents are::’
imsg_len:equ $-idtmsg

trmsg db 10,’Task Register Contents are::’
tmsg_len: equ $-trmsg

mswmsg db 10,’Machine Status Word::’
mmsg_len:equ $-mswmsg

colmsg db ‘:’

nwline db 10

section .bss
gdt resd 1
resw 1
ldt resw 1
idt resd 1
resw 1
tr  resw 1

cr0_data resd 1

dnum_buff resb 04

%macro disp 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .text
global _start
_start:
smsw eax        ;Reading CR0

mov [cr0_data],eax

bt eax,0        ;Checking PE bit(LSB), if 1=Protected Mode, else Real Mode
jc prmode
disp rmodemsg,rmsg_len
jmp nxt1

prmode:    disp pmodemsg,pmsg_len

nxt1:    sgdt [gdt]
sldt [ldt]
sidt [idt]
str [tr]

disp gdtmsg,gmsg_len

mov bx,[gdt+4]
call disp_num

mov bx,[gdt+2]
call disp_num

disp colmsg,1

mov bx,[gdt]
call disp_num

disp ldtmsg,lmsg_len
mov bx,[ldt]
call disp_num

disp idtmsg,imsg_len

mov bx,[idt+4]
call disp_num

mov bx,[idt+2]
call disp_num

disp colmsg,1

mov bx,[idt]
call disp_num

disp trmsg,tmsg_len

mov bx,[tr]
call disp_num

disp mswmsg,mmsg_len

mov bx,[cr0_data+2]
call disp_num

mov bx,[cr0_data]
call disp_num

disp nwline,1
exit:    mov eax,01
mov ebx,00
int 80h

disp_num:
mov esi,dnum_buff    ;point esi to buffer

mov ecx,04        ;load number of digits to display

up1:
rol bx,4        ;rotate number left by four bits
mov dl,bl        ;move lower byte in dl
and dl,0fh        ;mask upper digit of byte in dl
add dl,30h        ;add 30h to calculate ASCII code
cmp dl,39h        ;compare with 39h
jbe skip1        ;if less than 39h skip adding 07 more
add dl,07h        ;else add 07
skip1:
mov [esi],dl        ;store ASCII code in buffer
inc esi            ;point to next byte
loop up1        ;decrement the count of digits to display
;if not zero jump to repeat

disp dnum_buff,4    ;display the number from buffer
ret

OUTPUT:

cg-151@cg151:~$ cd Final\ MA/
cg-151@cg151:~/Final MA$ cd A10
cg-151@cg151:~/Final MA/A10$ nasm -f elf msmalc03.asm
cg-151@cg151:~/Final MA/A10$ ld -m elf_i386 -s -o msmalc03 msmalc03.o
cg-151@cg151:~/Final MA/A10$ ./msmalc03

Processor is in Protected Mode
GDT Contents are::0030A000:007F
LDT Contents are::0000
IDT Contents are::FF576000:0FFF
Task Register Contents are::0040
Machine Status Word::80050033
cg-151@cg151:~/Final MA/A10$

Share Button

Write ALP to find average of n numbers stored in memory.

Write ALP to find average of n numbers stored in memory.

; ALP for average of 32 bit numbers
;——————————————————————-
section    .data
nline        db    10,10
nline_len:    equ    $-nline

arr32        dd    00112233H, 00112233H, 00112233H, 00112233H, 00112233H
n:        equ    5
msg        db    10,10,”The average of 32-bit array elements is :    ”
msg_len:    equ    $-msg

;———————————————————————
Section   .bss
avg        resd    1
char_sum    resb    8
;———————————————————————
%macro  print   2
mov   eax, 4
mov   ebx, 1
mov   ecx, %1
mov   edx, %2
int   80h
%endmacro

%macro    exit    0
mov  eax, 1
mov  ebx, 0
int  80h
%endmacro

;———————————————————————
section    .text
global   _start
_start:

mov    esi, arr32
mov    edi, n

mov    eax, 0            ; sum register
mov    edx, 0            ; carry register
next_num:
add    eax,[esi]
jnc    skip
inc    edx
skip:
add     esi,4            ; 32 bit nos i.e. 4 bytes
dec     edi
jnz      next_num

mov    ebx,n            ; store array size in ebx
div    ebx            ; edx:eax / ebx
; average is in eax, remainder is in edx
mov    [avg], eax        ; store average

print    msg, msg_len

mov     eax,[avg]        ; load value of average in eax
call     disp32_proc        ; display average

print    nline, nline_len
exit
;——————————————————————–
disp32_proc:

mov     esi,char_sum+7        ; load last byte address of char_sum buffer in esi
mov     ecx,8            ; number of digits

cnt:    mov     edx,0            ; make edx=0 (as in div instruction edx:eax/ebx)
mov     ebx,16            ; divisor=16
div     ebx
cmp     dl, 9            ; check for remainder in EDX
jbe      add30
add      dl, 07h
add30:
add     dl,30h            ; calculate ASCII code
mov     [esi],dl        ; store it in buffer
dec     esi            ; point to one byte back

dec     ecx            ; decrement count
jnz     cnt            ; if not zero repeat

print char_sum,8        ; display result on screen
ret
;———————————————————–

OUTPUT:

cg-151@cg151:~$ cd Final\ MA/
cg-151@cg151:~/Final MA$ cd A8
cg-151@cg151:~/Final MA/A8$ nasm -f elf pn32.asm
cg-151@cg151:~/Final MA/A8$ ld -m elf_i386 -s -o pn32 pn32.o
cg-151@cg151:~/Final MA/A8$ ./pn32

The no. of Positive elements in 32-bit array :    00000003
The no. of Negative elements in 32-bit array :    00000002
cg-151@cg151:~/Final MA/A8$

Share Button

Write an ALP to count no. of positive and negative numbers from the array.

Write an ALP to count no. of positive and negative numbers from the array.

; ALP to find no. of positive / negative elements from 32-bit array
;——————————————————————-
section    .data
nline        db    10,10
nline_len:    equ    $-nline

arr32        dd    -11111111H, 22222222H, -33333333H, 44444444H, 55555555H
n:        equ    5
pmsg        db    10,10,”The no. of Positive elements in 32-bit array :    ”
pmsg_len:    equ    $-pmsg

nmsg        db    10,10,”The no. of Negative elements in 32-bit array :    ”
nmsg_len:    equ    $-nmsg

;———————————————————————
Section   .bss
p_count        resq    1
n_count        resq    1
char_count    resb    8    ; for 32-bit nos.
;———————————————————————

%macro  print   2
mov   eax, 4
mov   ebx, 1
mov   ecx, %1
mov   edx, %2
int   80h
%endmacro

%macro    exit    0
mov  eax, 1
mov  ebx, 0
int  80h
%endmacro

;———————————————————————

section    .text
global   _start
_start:

mov    esi, arr32
mov    edi, n

mov    ebx,0;            ; counter for     +ve nos.
mov    ecx,0;            ; counter for    -ve nos.

next_num:
mov    eax,[esi]        ; take no. in RAX
RCL    eax,1            ; rotate left 1 bit to check for sign bit
jc    negative

positive:
inc    ebx            ; no carry, so no. is +ve
jmp    next

negative:
inc    ecx            ; carry, so no. is -ve

next:
add     esi,4            ; 32 bit nos i.e. 4 bytes
dec     edi
jnz      next_num

mov    [p_count], ebx        ; store positive count
mov    [n_count], ecx        ; store negative count

print    pmsg, pmsg_len
mov     eax,[p_count]        ; load value of p_count in rax
call     disp32_proc        ; display p_count

print    nmsg, nmsg_len
mov     eax,[n_count]        ; load value of n_count in rax
call     disp32_proc        ; display n_count

print    nline, nline_len
exit
;——————————————————————–
disp32_proc:

mov     esi,char_count+7    ; load last byte address of char_count buffer in rsi
mov     ecx,8            ; number of digits

cnt:    mov     edx,0            ; make rdx=0 (as in div instruction rdx:rax/rbx)
mov     ebx,16            ; divisor=16 for hex
div     ebx
cmp     dl, 09h            ; check for remainder in RDX
jbe      add30
add      dl, 07h
add30:
add     dl,30h            ; calculate ASCII code
mov     [esi],dl        ; store it in buffer
dec     esi            ; point to one byte back

dec     ecx            ; decrement count
jnz     cnt            ; if not zero repeat

print char_count,8        ; display result on screen
ret
;———————————————————–

HOW TO RUN ?

cg-151@cg151:~$ cd Final\ MA/
cg-151@cg151:~/Final MA$ cd A8
cg-151@cg151:~/Final MA/A8$ nasm -f elf pn32.asm
cg-151@cg151:~/Final MA/A8$ ld -m elf_i386 -s -o pn32 pn32.o
cg-151@cg151:~/Final MA/A8$ ./pn32

The no. of Positive elements in 32-bit array :    00000003
The no. of Negative elements in 32-bit array :    00000002
cg-151@cg151:~/Final MA/A8$

 

Share Button

Write an ALP to read command line arguments passed to a program.

Write an ALP to read command line arguments passed to a program.

;Code for Write an ALP to read command line arguments passed to a program.
;Program displays the number of arguments and then the arguments

;No.of arguments:6

;Arguments are::

section .data
nomsg db 10,”No.of arguments:”
nomsg_len: equ $-nomsg

argmsg db 10,10,”Arguments are::”,10
argmsg_len: equ $-argmsg

nwline db 10
section .bss
arg resd 1
argcnt resd 1

%macro dispmsg 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 0x80
%endmacro

section .text
global _start
_start:
dispmsg nomsg,nomsg_len

;get no. of arguments
pop ecx
mov [argcnt],ecx

add ecx,’0′    ;Calculate ASCII code by adding 30h i.e. ‘0’
cmp ecx,39h
jbe skip
add ecx,07
skip:
mov [arg],ecx    ;store ASCII in temp location

;display no. of arguments
dispmsg arg,1

;display argument message
dispmsg argmsg,argmsg_len

;get pointer for args
next:     pop ecx
mov edx,00
up:     cmp byte [ecx+edx],0    ;check for end of argument
jz l1
inc edx
jmp up
l1:
mov eax,4
mov ebx,1
int 0x80

dispmsg nwline,1
dec dword [argcnt]
jnz next
exit:
mov eax,1
mov ebx,0
int 0x80

HOW TO RUN ?

;Code for Write an ALP to read command line arguments passed to a program.
;Program displays the number of arguments and then the arguments

;OUTPUT
; nasm -f elf32 msmalb07.asm
; ld -o msmalb07 msmalb07.o -m elf_i386
; ./msmalb07

OUTPUT:

cg-151@cg151:~/Final MA/A7$ nasm -f elf msmalb07.asm
cg-151@cg151:~/Final MA/A7$ ld -m elf_i386 -s -o msmalb07 msmalb07.o
cg-151@cg151:~/Final MA/A7$ ./msmalb07
No.of arguments:1
Arguments are::
./msmalb07
cg-151@cg151:~/Final MA/A7$

Share Button

Write a switch case driven ALP to perform 64-bit hexadecimal arithmetic operations (+,-,*, /) using suitable macros. Define procedure for each operation.

Write a switch case driven ALP to perform 64-bit hexadecimal arithmetic operations (+,-,*, /) using suitable macros. Define procedure for each operation.

;MALab Assignment B06
;Write a switch case driven ALP to perform 64-bit hexadecimal arithmetic operations (+,-,*, /) using suitable macros. Define procedure for each operation.

section .data
menumsg db 10,’****** Menu ******’,
db 10,’+: Addition’
db 10,’-: Subtraction’
db 10,’*: Multiplication’
db 10,’/: Division’
db 10,10,’Enter your choice:: ‘
menumsg_len: equ $-menumsg

addmsg db 10,’Welcome to additon’,10
addmsg_len equ $-addmsg
submsg db 10,’Welcome to subtraction’,10
submsg_len equ $-submsg
mulmsg db 10,’Welcome to Multiplication’,10
mulmsg_len equ $-mulmsg
divmsg db 10,’Welcome to Division’,10
divmsg_len equ $-divmsg
wrchmsg db 10,10,’Wrong CHoice Entered…!’,10
wrchmsg_len equ $-wrchmsg
msg db 10,10,”Dou want to continue?”
msglen equ $-msg

no1 dq 0ff05h
no2 dq 0ffh

resmsg db 10,’Result is:’
resmsg_len equ $-resmsg

qmsg db 10,’Quotient::’
qmsg_len equ $-qmsg

rmsg db 10,’Remainder::’
rmsg_len equ $-rmsg

nwmsg db 10

resh dq 0
resl dq 0

section .bss
accbuff resb 2
dispbuff resb 16

%macro  print   2
mov   eax, 4
mov   ebx, 1
mov   ecx, %1
mov   edx, %2
int   80h
%endmacro

section .text
global _start
_start:    print menumsg,menumsg_len

mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h

cmp byte [accbuff],’+’
jne case2

call add_proc
jmp exit
case2:
cmp byte [accbuff],’-‘
jne case3

call sub_proc
jmp exit
case3:
cmp byte [accbuff],’*’
jne case4

call mul_proc
jmp exit
case4:
cmp byte [accbuff],’/’
jne caseinv

call div_proc
jmp exit
caseinv:
print wrchmsg,wrchmsg_len

exit:    mov eax,01
mov ebx,0
int 80h

add_proc:
print addmsg,addmsg_len
mov rax,[no1]
add rax,[no2]
jnc addnxt1
inc qword [resh]
addnxt1:
mov [resl],rax
print resmsg,resmsg_len

mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1
print msg,msglen
mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h
cmp byte [accbuff],’y’
jne rtlp

call _start

sub_proc:
print submsg,submsg_len

mov rax,[no1]
sub rax,[no2]
jnc addnxt1
inc qword [resh]
subnxt1:
mov [resl],rax
print resmsg,resmsg_len

mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1
print msg,msglen
mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h
cmp byte [accbuff],’y’
jne rtlp

call _start

mul_proc:
print mulmsg,mulmsg_len
mov rax,[no1]
mov rbx,[no2]
mul rbx

mov [resh],rdx
mov [resl],rax

print resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1

print msg,msglen
mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h
cmp byte [accbuff],’y’
jne rtlp

call _start

div_proc:
print divmsg,divmsg_len

mov rax,[no1]
mov rdx,0
mov rbx,[no2]
div rbx

mov [resh],rdx    ;Remainder
mov [resl],rax    ;Quotient

print rmsg,rmsg_len
mov rbx,[resh]
call disp64num
print qmsg,qmsg_len
mov rbx,[resl]
call disp64num
print nwmsg,1
print msg,msglen
mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h
cmp byte [accbuff],’y’
jne rtlp

call _start

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

print dispbuff,16
ret
rtlp:
ret

OUTPUT:

cg-151@cg151:~/Final MA/A6$ nasm -f elf64 swcase.asm
cg-151@cg151:~/Final MA/A6$ ld -o swcase swcase.o
cg-151@cg151:~/Final MA/A6$ ./swcase

****** Menu ******
+: Addition
-: Subtraction
*: Multiplication
/: Division

Enter your choice:: +

Welcome to additon

Result is:00000000000000000000000000010004

Dou want to continue?y

****** Menu ******
+: Addition
-: Subtraction
*: Multiplication
/: Division

Enter your choice:: –

Welcome to subtraction

Result is:0000000000000000000000000000FE06

Dou want to continue?y

****** Menu ******
+: Addition
-: Subtraction
*: Multiplication
/: Division

Enter your choice:: *

Welcome to Multiplication

Result is:00000000000000000000000000FE05FB

Dou want to continue?y

****** Menu ******
+: Addition
-: Subtraction
*: Multiplication
/: Division

Enter your choice:: /

Welcome to Division

Remainder::0000000000000005
Quotient::0000000000000100

Dou want to continue?n
cg-151@cg151:~/Final MA/A6$

Share Button

Write an ALP to fond the largest of given byte/Word/Dword/64-bit numbers.

Write an ALP to fond the largest of given byte/Word/Dword/64-bit numbers

;     Find largest number from the array of 32-bit numbers.
;    Program first displays all the elements of array.
;    Then it search for largest number and display the same.

section .data

wel_msg db ‘Welcome to find largest number by MBS!’,10
wel_len: equ $-wel_msg

arr_msg db ‘Array Elements Are:: ‘,10
arr_len : equ $-arr_msg

larg_msg db ‘Largest Number is::’
larg_len: equ $-larg_msg

thankmsg db 10,’THANK YOU BY SSIERAS RAHATA’,10
thank_len : equ $-thankmsg

nwline db 10

array dd 0fa100001h,0b200002h,0fff0003h,0d400004h, 0500005h        ;array elements
arrcnt dd 05h

section .bss
dnum_buff resb 8
large resd 1

%macro dispmsg 2
mov eax,4    ;System call for write
mov ebx,1    ;standard output stream
mov ecx,%1    ;message start address
mov edx,%2    ;message length
int 80h
%endmacro

section .text
global _start
_start:
dispmsg wel_msg,wel_len
dispmsg arr_msg,arr_len
mov esi,array
mov ecx,[arrcnt]

up1:    mov ebx,[esi]
push ecx
call disp_num
dispmsg nwline,1
pop ecx
add esi,04    ;Point to next element

loop up1

mov esi,array
mov ecx,[arrcnt]
mov eax,[esi]
dec ecx

lup1:    add esi,04    ;Point to next element
cmp eax,[esi]
ja lskip1
xchg eax,[esi]
lskip1:
loop lup1
mov [large],eax

dispmsg larg_msg,larg_len
mov ebx,[large]
call disp_num

dispmsg thankmsg,thank_len

exit:    mov eax,01
mov ebx,0
int 80h

disp_num:
mov edi,dnum_buff    ;point esi to buffer

mov ecx,8        ;load number of digits to display

dispup1:
rol ebx,4        ;rotate number left by four bits
mov dl,bl        ;move lower byte in dl
and dl,0fh        ;mask upper digit of byte in dl
add dl,30h        ;add 30h to calculate ASCII code
cmp dl,39h        ;compare with 39h
jbe dispskip1        ;if less than 39h akip adding 07 more
add dl,07h        ;else add 07

dispskip1:
mov [edi],dl        ;store ASCII code in buffer
inc edi            ;point to next byte
loop dispup1        ;decrement the count of digits to display
;if not zero jump to repeat

dispmsg dnum_buff,8
ret

OUTPUT:

cg-151@cg151:~/Final MA/A5$ nasm -f elf largest32.asm
cg-151@cg151:~/Final MA/A5$ ld -m elf_i386 -o largest32 largest32.o
cg-151@cg151:~/Final MA/A5$ ./largest32
Welcome to find largest number by MBS!
Array Elements Are::
FA100001
0B200002
0FFF0003
0D400004
00500005
Largest Number is::FA100001
THANK YOU BY SSIERAS RAHATA
cg-151@cg151:~/Final MA/A5$

Share Button

Write an ALP to accept a string and to display it’s length.

3. Write an ALP to accept a string and to display it’s length.

section .bss
strng    resb 10
len_hex resd 1
len_ascii resd 1

section .data
msg    db     10, “enter the string  :   ”
msglen  equ      $-msg
msg2    db    10, “the string is     :   ”
msg2len equ    $-msg2
msg3    db    10, “the length is    :    ”
msg3len    equ    $-msg3
newline    db    0ah

section .text
global _start

_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msglen
int 80h

mov eax, 3
mov ebx, 0
mov ecx, strng
mov edx, 10
int 80h

dec eax
mov [len_hex], eax
cmp eax, 09h
jbe add_30h
add eax, 07h
add_30h:
add eax, 30h

mov [len_ascii], eax

; display stng

mov eax, 4 ;display the msg “the name is”
mov ebx, 1
mov ecx, msg2
mov edx, msg2len
int 80h

mov eax, 4   ; display actual name which was read from kb
mov ebx, 1
mov ecx, strng
mov edx, [len_hex]
int 80h

;display len

mov eax, 4    ; display msg “length is”
mov ebx, 1
mov ecx, msg3
mov edx, msg3len
int 80h

mov eax, 4    ; display the actual length
mov ebx, 1
mov ecx, len_ascii
mov edx, 4
int 80h

mov eax, 4    ; display new_line
mov ebx, 1
mov ecx, newline
mov edx, 1
int 80h

mov eax, 1 ;sys_exit call
mov ebx, 0
int 80h

OUTPUT:

cg-151@cg151:~/Final MA/A3$ nasm -f elf string.asm
cg-151@cg151:~/Final MA/A3$ ld -m elf_i386 -s -o string string.o
cg-151@cg151:~/Final MA/A3$ ./string

enter the string  :   saibaba
the string is     :   saibaba
the length is    :    7
cg-151@cg151:~/Final MA/A3$

Share Button

Write an ALP to accept ten 32-bit and 64 bit Hexadecimal numbers from user and store then in data segment table and display then numbers.

2. Write an ALP to accept ten 32-bit and 64 bit Hexadecimal numbers from user and store then in data segment table and display then numbers.

; accept 3 32bit hex numbers, save them in an array and display them

section .bss

num    resd    3   ; array “num” each element 32bit, 3 elements    ; space reserved

section .data
msg    db    “enter hex number”, 10
msglen    equ    $-msg
msg1    db    “The numbers are”, 10
msg1len    equ    $-msg1
%macro disp  2
mov eax, 4
mov ebx, 1
mov ecx,%1
mov edx, %2
int 80h
%endmacro
section .text
global  _start

_start:

;accept number

mov esi, num
mov edi, 3
nxt_num:

disp msg, msglen
mov eax, 3        ;sys_read function number
mov ebx, 0
mov ecx, esi
mov edx, 4
int 80h

add esi, 4
dec edi
jnz nxt_num

;display num

mov esi, num
mov edi, 3
disp msg1, msg1len
nxt_num1:

mov eax, 4        ;sys-write function number
mov ebx, 1
mov ecx, esi
mov edx, 4
int 80h

add esi, 4
dec edi
jnz nxt_num1

mov eax, 1
mov ebx, 0
int 80h

Output:

cg-151@cg151:~/Final MA/A2$ nasm -f elf array.asm
cg-151@cg151:~/Final MA/A2$ ld -m elf_i386 -s -o array array.o
cg-151@cg151:~/Final MA/A2$ ./array
enter hex number
AA
enter hex number
BB
enter hex number
CC
The numbers are
AA
BB
CC
cg-151@cg151:~/Final MA/A2$

Share Button

Write ALP to print “Hallo World!” Program using 16, 32 and 64-bit model.

  1. Write ALP to print “Hallo World!” Program using 16, 32 and 64-bit model and segmentation.

;ALP TO PRINT “HELLO WORLD” PROGRAM USING 64 BIT MODEL
;NAME :
;ROLL NO. :

global _start            ; global entry point export for ld

section .text
_start:

; sys_write(stdout, message, length)

mov    rax, 1        ; sys_write
mov    rdi, 1        ; stdout
mov    rsi, message    ; message address
mov    rdx, length    ; message string length
syscall

; sys_exit(return_code)

mov    rax, 60        ; sys_exit
mov    rdi, 0        ; return 0 (success)
syscall

section .data
message: db ‘Hello, world to PREC !’,0x0A    ; message and newline
length:    equ    $-message        ; NASM definition pseudo-instruction

 

OUTPUT:

cg-151@cg151:~/Final MA/A1$ nasm -f elf hello32.asm
cg-151@cg151:~/Final MA/A1$ ld -m elf_i386 -s -o hello32 hello32.o
cg-151@cg151:~/Final MA/A1$ ./hello32
Hello, world to SSIERAS Rahata !
cg-151@cg151:~/Final MA/A1$ ^C
cg-151@cg151:~/Final MA/A1$

Share Button