Name:
Registration Number:
Course: Computer Organization and Assembly Language (Lab)
Teacher Name:
Q.1)
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 'Displaying 9 stars',0xa ;a message
len equ $ - msg ;length of message
s2 times 9 db '*'
ection .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
Q.2)
.MODEL SMALL
.DATA
NUM_1 DB ?
NUM_2 DB ?
NUM_3 DB ?
V1 DB ?
V2 DB ?
NL DB ' ', 0DH,0AH,'$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DX,AX
MOV CX,10
MOV CH,0
MOV NUM_1,0
MOV NUM_2,1
MOV DL,NUM_1
OR DL,30H
MOV AH,02H
INT 21H
MOV DL,NUM_2
OR DL,30H
MOV AH,02H
INT 21H
L1:
MOV AL,NUM_1
ADD AL,NUM_2
MOV AH,0
MOV BL,AL
MOV DL,10
DIV DL
ADD AX,3030H
MOV V1,AL
MOV V2,AH
MOV DL,V1
MOV AH,02H
INT 21H
MOV DL,V2
MOV AH,02H
INT 21H
SHIFT:
MOV AL,NUM_2
MOV NUM_1,AL
MOV NUM_2,BL
LOOP L1
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
;***************
; OUTPUT
;***************
;0 1 01 02 03 05 08 13 21 34 55 89
Q3)
section.data
section.text
global _start
_start:
ection .text
global _start ;must be declared for linker (ld)
_start: ;tells 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 ;string to be printed
len equ $ - msg ;length of the string
segment .text ;code segment
global _start ;must be declared for linker
_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
segment .data ;data segment
msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string