0% found this document useful (0 votes)
67 views6 pages

Assignment 01: Ques1) Write Program To Print "Hello World"

The document contains code snippets and output from 4 programming assignments: 1) Two programs that print "hello world" and "Hello, this is my first program" using two sections. 2) A program that prints 9 stars. 3) A program that reads a number from keyboard and displays it. 4) A program that stores a number in memory, changes it, and displays both numbers.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views6 pages

Assignment 01: Ques1) Write Program To Print "Hello World"

The document contains code snippets and output from 4 programming assignments: 1) Two programs that print "hello world" and "Hello, this is my first program" using two sections. 2) A program that prints 9 stars. 3) A program that reads a number from keyboard and displays it. 4) A program that stores a number in memory, changes it, and displays both numbers.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

0801IT211098

Yash Rughwani
ASSIGNMENT 01

Ques1) Write program to print “hello world”.


Program:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov edx, len ;message length
mov ecx, msg ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data

msg db 'Hello, world!',0xa ;our dear string


len equ $ - msg ;length of our dear string

Output:

Ques2) Write a program to print hello, this is my first program using two sections
Program:
section .text
global _start ;must be declared for linker (gcc)
_start: ;tell linker entry point

mov edx,len ;message length


mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov edx,len1 ;message length


mov ecx,msg1 ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
msg db 'Hello World, ',0xa ;a message
len equ $ - msg ;length of message

section .data
msg1 db 'This is my first program ',0xa ;a message
len1 equ $ - msg ;length of message

Output:

0801IT211098
Yash Rughwani
ASSIGNMENT 02

Ques1) Write a program to print 9 stars.


Program:
section .text
global _start ;must be declared for linker (gcc)
_start: ;tell linker entry point

mov edx,len ;message length


mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov edx,9 ;message length


mov ecx,s2 ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
msg db '9 stars are',0xa ;a message
len equ $ - msg ;length of message
s2 times 9 db '*'

Output:

0801IT211098
Yash Rughwani
ASSIGNMENT 03

Ques1) Write program to read a number from the keyboard and display it on the screen.
Program:
section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg

section .bss ;Uninitialized data


num resb 5

section .text ;Code Segment


global _start

_start: ;User prompt


mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h

;Read and store the user input


mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h

;Output the message 'The entered number is: '


mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h

;Output the number entered


mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h

Output:

0801IT211098
Yash Rughwani
ASSIGNMENT 04
Ques1) 1. Write a program to store a number in the data section of the memory, then
change its value to another number programmatically and displays both the numbers.
Program:
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point

;writing the number '35'


mov edx,3 ;message length
mov ecx, num ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov [num], dword '4555' ; Changed the name to 4555

;writing the number '4555'


mov edx,5 ;message length
mov ecx,num ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
num db '35 '

Output:

You might also like