Assignment No. 8

Write a TSR program in 8086 ALP to implement Screen Saver. Screen Saver should get activated if the keyboard is idle for 7 seconds. Access the video RAM directly in your routine.

MESS MACRO MSG
MOV AH,09H
MOV DX,OFFSET MSG
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 10,13,”THE TIME IS=$”
TIME DB “00:00:00$”
.CODE
MOV AX,@DATA
MOV DS,AX
MESS MSG1
MOV BX,OFFSET TIME
CALL GETTIME
MOV AH,09H
MOV DX,OFFSET TIME
INT 21H
MOV AH,4CH
INT 21H

GETTIME PROC NEAR
MOV AH,2CH
INT 21H
MOV AL,CH
CALL CONVERT
MOV [BX],AX
MOV AL,CL
CALL CONVERT
MOV [BX+3],AX
MOV AL,DH
CALL CONVERT
MOV [BX+6],AX
RET
GETTIME ENDP

CONVERT PROC NEAR
MOV AH,0
MOV DL,10
DIV DL
OR AX,3030H
RET
CONVERT ENDP
END

————————————————-OUTPUT————————————————-

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Dhokane>d:

D:\>tasm MYTIME.ASM
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   MYTIME.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  476k

D:\>tlink MYTIME.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International

D:\>MYTIME

THE TIME IS=10:52:48
D:\>

Share Button

Assignment No. 5

Write 8086 ALP to perform string manipulation. The strings to be accepted from the user is to be stored in data segment of program_l and write FAR PROCEDURES in code segment program_2 for following operations on the string: (a)Concatenation of two strings (b) Number of occurrences of a sub-string in the given string Use PUBLIC and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.

In this program create 3 files as follows
1. file1.asm
2. file2.asm
3. macro.asm

1. file1.asm
——————————————————————————————–
;Assignment Name :X86/64 Assembly language program (ALP)
;String Manipulation : Concatenation of 2 strings &
;Find no. of occurences of substring.
;Accept string from user.
;————————————————————————

extern    con_proc        ; [ FAR PROCRDURE
extern    sub_proc        ;   USING EXTERN DIRECTIVE ]

global    str1,str1_size, str2, str2_size

%include    “macro.asm”

;————————————————————————
section .data
nline        db    10,10
nline_len:    equ    $-nline

msg        db     10,10,10,10,”MIL assignment 07 : String Manipulation”
db    10,”————————————-“,10
msg_len:    equ    $-msg

s1msg        db    10,”Enter string 1    : ”
s1msg_len:    equ    $-s1msg

s2msg        db    10,”Enter string 2    : ”
s2msg_len:    equ    $-s2msg

menu        db    10,”———–MENU———————”
db    10,”1.String Concatenation”
db    10,”2.No. of occurences of substring”
db    10,”3.Exit”
db    10,”Enter choice    : ”
menu_len:    equ    $-menu

emsg        db    10,”INVALID CHOICE!!!!! Please try again! “,10,10,10
emsg_len:    equ    $-emsg

;—————————————————————————
section .bss
buf        resb    2
buf_len:    equ    $-buf

str1        resb    20
str1_len:    equ    $-str1

str2        resb    20
str2_len:    equ    $-str2

str1_size    resw    1
str2_size    resw    1

;————————————————————————–
section .text
global _start

_start:
print    msg,msg_len        ;assignment no.

print    s1msg,s1msg_len
read     str1,str1_len
dec    eax
mov    [str1_size],ax

print    s2msg,s2msg_len
read     str2,str2_len
dec    eax
mov    [str2_size],ax

Disp_Menu:
print    menu,menu_len
read    buf,2
mov    al,[buf]
SUB    AL,30H

C1:      CMP    al,1
JNE    C2
call    con_proc
JMP    Disp_Menu

C2:      CMP    al,2
JNE    C3
call    sub_proc
JMP    Disp_Menu

C3:    CMP    al,3
JNE    err
exit

err:    print    emsg,emsg_len
JMP    Disp_Menu
;——————————————————————————–
2. file2.asm
;———————————————————————
section .data
nline        db    10,10
nline_len:    equ    $-nline

cmsg        db    10,”The Concatenated String is    : ”
cmsg_len:    equ    $-cmsg

ymsg        db    10,”The substring is Present.”,10
db    10,”No. of occurences of substring    : ”
ymsg_len:    equ    $-ymsg

nmsg        db    10,”The substring is not Present.”,10
db    10,”No. of occurences of substring    : ”
nmsg_len:    equ    $-nmsg
;———————————————————————

section .bss
str3        resb    40
str3_len:    equ    $-str3

str3_size    resw    1

sscount        resw    1
cur_add        resq    1
end_add        resq    1

char_ans    resb    4
;———————————————————————

extern    str1,str1_size, str2, str2_size
global    con_proc, sub_proc

%include    “macro.asm”
;———————————————————————
section .text
global    _main
_main:
;    global    con_proc, sub_proc

con_proc:                  ;STRING CONCATINATION PROCEDURE
cld

mov    ecx,0
mov    cx,[str1_size]
mov    esi, str1        ; 1st string

mov    edi, str3        ; concatenated string
rep     movsb

mov    ecx,0
mov    cx,[str2_size]
mov    esi, str2        ; 2nd string

rep     movsb

mov    cx,[str1_size]
add    cx,[str2_size]
mov    [str3_size],cx

print cmsg,cmsg_len
print str3,str3_len

ret
;———————————————————————
sub_proc:                ;substring procedure

mov    esi,str1

CLD

mov    [cur_add],esi        ; store starting address of string1

mov    ecx,esi            ; calculate end address of string1
add    cx,[str1_size]
dec    ecx
mov    [end_add],ecx

back:
mov    edi,str2
xor    ecx,ecx
mov    cx,[str2_size]

repe     cmpsb

jnz     conti
inc     word[sscount]

conti:
inc     word[cur_add]
mov     esi,[cur_add]
cmp      esi,[end_add]
jbe     back

cmp     word[sscount],00
je     no

print     ymsg, ymsg_len
jmp     last

no:    print     nmsg, nmsg_len

last:
mov     ax,[sscount]
call     display_16

ret
;——————————————————————
display_16:
mov     esi,char_ans+3    ; load last byte address of char_ans in rsi
mov     ecx,4            ; 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_ans,4        ; display result on screen
ret
;—————————————————————-

3. macro.asm

————————————————————————————
;macro.asm
;macros as per 64 bit conventions

%macro print 2
mov    eax,4        ;print/write
mov    ebx,1        ;stdout/screen
mov    ecx,%1    ;msg
mov    edx,%2    ;msg_len
int 80h
%endmacro

%macro read 2
mov    eax,3        ;read
mov    ebx,0        ;stdin/keyboard
mov    ecx,%1    ;buf
mov    edx,%2    ;buf_len
int 80h
%endmacro

%macro exit 0
print    nline,nline_len
mov    eax,1    ;exit
int 80h
%endmacro
———————————————————————————————————————-
Steps to run the program as follows

dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX/far procedure$ nasm -f elf file1.asm
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX/far procedure$ nasm -f elf file2.asm
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX/far procedure$ ld -m elf_i386 -s -o file1 file1.o -o file2 file2.o
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX/far procedure$ ./file2

MIL assignment 07 : String Manipulation
————————————-

Enter string 1    : abcabcabcabcabc

Enter string 2    : abc

———–MENU———————
1.String Concatenation
2.No. of occurences of substring
3.Exit
Enter choice    : 1

The Concatenated String is    : abcabcabcabcabcabc
———–MENU———————
1.String Concatenation
2.No. of occurences of substring
3.Exit
Enter choice    : 2

The substring is Present.

No. of occurences of substring    : 0005
———–MENU———————
1.String Concatenation
2.No. of occurences of substring
3.Exit
Enter choice    : 3

Share Button

Assignment No. 4

Write X86/64 ALP for the following operations on the string entered by the user. (Use of 64-bit registers is expected) c) Check whether the string is palindrome) Calculate Length of the string b) Reverse the string

;Program for string operation
;——————-p4.asm———————————————–
%macro dispmsg 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,03
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro acceptstr 1
mov eax,03
mov ebx,0
mov ecx,%1
int 80h
%endmacro

section .data
menumsg db 10,10,’##### Menu for String Operations #####’
db 10,13,’1.Enter the String’
db 10,13,’2.Calculate the length’
db 10,13,’3.Reverse the String’
db 10,13,’4.Check Whether String is Palindrome or not’
db 10,13,’5.Exit’,10
db 10,13,’Enter your Choice’

menumsg_len equ $-menumsg
wrchmsg db 10,10,’Wrong Choice Entered….Please try again!!!’,10,10
wrchmsg_len equ $-wrchmsg

entmsg db 10,’Enter the String::’
entmsg_len equ $-entmsg

lmsg db 10,’Length of the String is::’
lmsg_len equ $-lmsg

revmsg db 10,’Revered String is ::’
revmsg_len equ $-revmsg

palmsg db 10,’String is Palindrome !’
palmsg_len equ $-palmsg

npalmsg db 10,’String is not Palindrome !’
npalmsg_len equ $-npalmsg

restmsg db 10,’Do you want to continue ?’
restmsg_len equ $-restmsg

thankmsg db 10,10,’Thank you for using Program created by Prof. Dhokane R.M.!!’,10
thankmsg_len equ $-thankmsg

spacechar db 20h

section .bss
cnt resb 01
optionbuff resb 02
dispbuff resb 03
srcstr resb 10
revstr resb 10
string resb 0

section .text
global _start
_start:

menu:    dispmsg menumsg,menumsg_len

accept optionbuff,02

cmp byte [optionbuff],’1′
jne case2
call entstr_proc
jmp exit1

case2:    cmp byte [optionbuff],’2′
jne case3
call length_proc
jmp exit1

case3:    cmp byte [optionbuff],’3′
jne case4
call reverse_proc
jmp exit1

case4:    cmp byte [optionbuff],’4′
jne case5
call pal_proc
jmp exit1

case5:    cmp byte [optionbuff],’5′
je exit

dispmsg wrchmsg,wrchmsg_len
jmp menu
exit1:
dispmsg restmsg,restmsg_len
accept optionbuff,02
cmp byte [optionbuff],’y’
jne y1
jmp menu
y1:     cmp byte [optionbuff],’Y’
jne exit
jmp menu

exit:
dispmsg thankmsg,thankmsg_len

mov eax,01    ;Exit
mov ebx,0
int 80h

dispblk_proc:
mov ecx,cnt
rdisp:
push ecx
mov bl,[esi]        ;Read ASCII value char by char
call disp8_proc        ;& Display
inc esi            ;Point to next char
dispmsg spacechar,1    ;Display space
pop ecx
loop rdisp        ;Decrement count
;Repeat display process till actual count becomes zero
ret

entstr_proc:
dispmsg entmsg,entmsg_len
acceptstr srcstr
dec al
mov [cnt],al
ret

length_proc:
dispmsg lmsg,lmsg_len
mov bl,[cnt]
call disp8_proc
ret

reverse_proc:
mov ecx,00
mov esi,srcstr
mov edi,revstr
mov cl,[cnt]
add esi,ecx
sub esi,1
up2: mov al,[esi]
mov [edi],al
inc edi
dec esi
loop up2
dispmsg revmsg,revmsg_len
dispmsg revstr,cnt
ret

pal_proc:
mov ecx,00
mov esi,srcstr
mov edi,revstr
mov cl,[cnt]
up3:    mov al,[esi]
mov bl,[edi]
cmp al,bl
jne exit2
inc esi
inc edi
loop up3
dispmsg palmsg,palmsg_len
jmp return
exit2:  dispmsg npalmsg,npalmsg_len
return:    ret

disp8_proc:
mov ecx,02
mov edi,dispbuff
dup1:
rol bl,4
mov al,bl
and al,0Fh
cmp al,09h
jbe dskip
add al,07h
dskip:    add al,30h
mov [edi],al
inc edi
loop dup1

dispmsg dispbuff,03
ret
;—————————————————————————————————————————–
Steps to execute the above program is as follows:

dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ nasm -f elf p4.asm
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ld -m elf_i386 -s -o p4  p4.o
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ./p4

##### Menu for String Operations #####
1.Enter the String
2.Calculate the length
3.Reverse the String
4.Check Whether String is Palindrome or not
5.Exit

Enter your Choice1

Enter the String::engineering

Do you want to continue ?y

##### Menu for String Operations #####
1.Enter the String
2.Calculate the length
3.Reverse the String
4.Check Whether String is Palindrome or not
5.Exit

Enter your Choice2

Length of the String is::0B
Do you want to continue ?y

##### Menu for String Operations #####
1.Enter the String
2.Calculate the length
3.Reverse the String
4.Check Whether String is Palindrome or not
5.Exit

Enter your Choice3

Revered String is ::gnireenigne
Do you want to continue ?y

##### Menu for String Operations #####
1.Enter the String
2.Calculate the length
3.Reverse the String
4.Check Whether String is Palindrome or not
5.Exit

Enter your Choice4

String is not Palindrome !
Do you want to continue ?y

##### Menu for String Operations #####
1.Enter the String
2.Calculate the length
3.Reverse the String
4.Check Whether String is Palindrome or not
5.Exit

Enter your Choice5
Thank you for using Program created by Prof. Dhokane R.M.!!
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$

Share Button

Assignment No. 3

Write 64 bit ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for: a) HEX to BCD b) BCD to HEX (c) EXIT.

;x86 ALP for Hex to BCD and BCD to Hex Conversion
;As per the statement we need to write 64-bit ALP.
;Use this code for reference only and not as a final program
;Use syscall and 64-bit registers to convert the code to 64-bit
;——————-p3.asm——————————————————————

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

%macro accept 2
mov eax,03
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro exit 0
dispmsg thankmsg,thankmsg_len
mov eax,01        ;Exit
mov ebx,00
int 80h
%endm exit

section .data
menumsg db 10,10,’###### Menu for Code Conversion ######’
db 10,13,’1: Hex to BCD’
db 10,13,’2: BCD to Hex’
db 10,13,’3: Exit’
db 10,10,’Please Enter Choice::’
menumsg_len equ $-menumsg
wrchmsg db 10,10,’Wrong Choice Entered….Please try again!!!’,10,10
wrchmsg_len equ $-wrchmsg

hexinmsg db 10,10,’Please enter 4 digit hex number::’
hexinmsg_len equ $-hexinmsg

bcdopmsg db 10,10,’BCD Equivalent::’
bcdopmsg_len equ $-bcdopmsg

bcdinmsg db 10,10,’Please enter 5 digit BCD number::’
bcdinmsg_len equ $-bcdinmsg

hexopmsg db 10,10,’Hex Equivalent::’
hexopmsg_len equ $-hexopmsg

thankmsg db 10,13,’Thank you for using Program by Prof. Dhokane Rahul’
thankmsg_len equ $-thankmsg

section .bss
numascii resb 06        ;common buffer for choice, hex and bcd input
opbuff resb 05
dnumbuff resb 08

section .text
global _start
_start:

dispmsg menumsg,menumsg_len
accept numascii,2

cmp byte [numascii],’1′
jne case2
call hex2bcd_proc

jmp _start

case2:    cmp byte [numascii],’2′
jne case3
call bcd2hex_proc
jmp _start

case3:    cmp byte [numascii],’3′
je exit
dispmsg wrchmsg,wrchmsg_len
jmp _start

exit

hex2bcd_proc:
dispmsg hexinmsg,hexinmsg_len
accept numascii,5
call packnum
mov ecx,5
mov ax,bx
mov bx,10
h2bup1:    mov dx,0
div bx
push edx
loop h2bup1
mov edi,opbuff
mov ecx,5
h2bup2:    pop edx
add dl,30h
mov [edi],dl
inc edi
loop h2bup2

dispmsg bcdopmsg,bcdopmsg_len
dispmsg opbuff,5
ret

bcd2hex_proc:
dispmsg bcdinmsg,bcdinmsg_len
accept numascii,6

dispmsg hexopmsg,hexopmsg_len

mov esi,numascii
mov ecx,05
mov eax,0
mov ebx,0ah

b2hup1:    mov edx,0
mul ebx
mov dl,[esi]
sub dl,30h
add eax,edx
inc esi
loop b2hup1
mov ebx,eax
call disp32_num
ret

packnum:
mov bx,0
mov ecx,04
mov esi,numascii
up1:
rol bx,04
mov al,[esi]
cmp al,’9′
jbe sub30
cmp al,’F’
jbe sub37
cmp al,’f’
jbe sub57
sub57:    sub al,20h
sub37:    sub al,07h
sub30:    sub al,30h
add bl,al
inc esi
loop up1
ret

disp32_num:
mov edi,dnumbuff    ;point esi to buffer

mov ecx,08        ;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 dnumbuff+3,5
ret

;——————————————————————————————————————
Steps to run the above program is as follows:

dhokane@dhokane-ThinkCentre-A70:~$ nasm -f elf p3.asm
dhokane@dhokane-ThinkCentre-A70:~$ ld -m elf_i386 -s -o p3  p3.o
dhokane@dhokane-ThinkCentre-A70:~$ ./p3

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::1

Please enter 4 digit hex number::ffff

BCD Equivalent::65535

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::2

Please enter 5 digit BCD number::65535

Hex Equivalent::0FFFF

###### Menu for Code Conversion ######
1: Hex to BCD
2: BCD to Hex
3: Exit

Please Enter Choice::3
Thank you for using Program by Prof. Dhokane Rahul
dhokane@dhokane-ThinkCentre-A70:~$

Share Button

Assignment No. 2

Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment.

;Write X86/64 ALP to perform non-overlapped and overlapped block transfer
;(with and without string specific instructions).
;Block containing data can be defined in the data segment.
;Macro Deffination
;—————————————————————————————
%macro exit 0
mov eax,1
int 80h
%endm exit

%macro accept 2  ;macro for read
mov eax,3        ;system call for read
mov ebx,0
mov ecx,%1
mov edx,%2       ;format for collecting arguments(as buffer_name & buffer_size)
int 80h
%endmacro

%macro disp 2   ;macro for display
mov eax,4       ;system call for display
mov ebx,1
mov ecx,%1      ;format for collecting arguments(as buffer_name & buffer_size)
mov edx,%2
int 80h
%endmacro

section .data
srcblk db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah
destblk times 10 db 00

mn    db 10,13,’*****MENU*****’
db 10,13,’1.Non Overlap Block Transfer’
db 10,13,’2.Overlap Block Transfer’
db 10,13,’3.Exit’
db 10,13,’Enter Choice=’
mnlen equ $-mn

msg0 db ‘ ‘
msg0len equ $-msg0

msg1 db 10,13,’Array before bloktransfer’
len1 equ $-msg1

msg2 db 10,13,’Array after bloktransfer=’
len2 equ $-msg2

msg3 db 10,13,’Source Array=’
len3 equ $-msg3

msg4 db 10,13,’Dest Array=’
len4 equ $-msg4

newln db 10,13,”
lnlen equ $-newln

cnt equ 10

section .bss
cho resb 2
chlen equ $-cho
ansfin resb 2
ansfinlen equ $-ansfin

section .text
global _start
_start:
disp newln,lnlen
disp mn,mnlen
accept cho,chlen
cmp byte[cho],’1′
je nonover
cmp byte[cho],’2′
je ovr
disp newln,lnlen
exit

ovr:
call over
nonover:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,cnt
call display

disp msg4,len4
mov esi,destblk
mov ebp,cnt
call display

disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,cnt
call display

mov esi,srcblk
mov edi,destblk
mov ecx,cnt
cld
rep movsb

disp msg4,len4
mov esi,destblk
mov ebp,cnt
call display
jmp _start

over:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,cnt
call display

disp msg4,len4
mov esi,destblk
mov ebp,cnt
call display

disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,cnt
call display

mov esi,srcblk
mov edi,destblk
mov ecx,10
cld
rep movsb
mov esi,srcblk
mov edi,destblk+5
mov ecx,5
cld
rep movsb

disp msg4,len4
mov esi,destblk
mov ebp,cnt
call display
jmp _start

numascii:
mov edi,ansfin+1
mov ecx,2
l2:
mov edx,0
mov ebx,16
div ebx
cmp dl,09h
jbe add30
add dl,07h
add30:
add dl,30h
mov [edi],dl
dec edi
dec ecx
jnz l2
disp ansfin,ansfinlen
ret

display:
l1:
mov eax,[esi]
call numascii
disp msg0,msg0len
inc esi
dec ebp
jnz l1
ret
;—————————————————————————————————
Steps to execute the above code is as follows:

sai@sai-ThinkCentre-A70:~$ nasm -f elf p2.asm
sai@sai-ThinkCentre-A70:~$ ld -m elf_i386 -s -o p2 p2.o
sai@sai-ThinkCentre-A70:~$ ./p2

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=1

Array before block transfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=00 00 00 00 00 00 00 00 00 00

Array after block transfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=2

Array before block transfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A

Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 01 02 03 04 05

*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=3

sai@sai-ThinkCentre-A70:~$

Share Button

Assignment No. 1

Write X86/64 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the
memory. Accept input from the user.

;MIL Assignment No. 1
;X86/64 Assembly language program (ALP)
;Addition of N 16-bit nos, result is 32 bit.
;Accept input from the user. Display the result.

;macros as per 64-bit convensions
;—————————————————————————–
%macro  print   2
mov     eax,4        ; Function 1 – write
mov     ebx,1        ; To stdout
mov     ecx,%1        ; String address
mov     edx,%2        ; String size
int 80h            ; invoke operating system to WRITE
%endmacro print%macro  read   2
mov     eax,3        ; Function 0 – Read
mov     ebx,0        ; from stdin
mov     ecx,%1        ; buffer address
mov     edx,%2        ; buffer size
int 80h            ; invoke operating system to READ
%endmacro read

%macro    exit    0
mov eax, 1        ; system call 60 is exit
int 80h             ; invoke operating system to exit
%endmacro exit
;——————————————————————

;———————————————————————
section .data
nline        db    10,10
nline_len:    equ    $-nline

msg         db     10,13,”MIL assignment 01 : Addition of N 16-bit nos.”
db    10,13,”———————————————”
msg_len:    equ     $-msg

smsg         db     10,13,”Enter size of array <????> = ”
smsg_len:    equ     $-smsg

amsg         db     10,13,”Enter data <????>    = ”
amsg_len:    equ     $-amsg

dmsg         db     10,13,”Result <????????>    = ”
dmsg_len:    equ     $-dmsg

emsg         db     10,13,”You entered Invalid Data!!!”,10
emsg_len:    equ     $-emsg
;———————————————————————
section .bss
buf         resb     5        ;4digits + enter
buf_len:    equ     $-buf
size        resw    1
ansl        resw    1
ansh        resw    1
char_ans    resb    4
;———————————————————————
section .text
global _start
_start:
print    msg,msg_len    ; “MIL assignment 01 : Addition of N 16-bit nos.”

print    smsg,smsg_len    ; “Enter size of array <????> = ”
call    accept_16
mov    [size],bx

mov     ebp,[size]
next_num:
print    amsg,amsg_len    ; “Enter data <????>    = ”
call    accept_16
add    [ansl],bx
jnc    next

inc    word [ansh]
next:    dec    ebp
jnz    next_num

print     dmsg,dmsg_len    ; “Result <???? ????>    = ”
mov     eax,[ansh]    ; load value of ansh in rax
call     display_16    ; display result

mov     eax,[ansl]    ; load value of ansl in rax
call     display_16    ; display result

print    nline, nline_len
exit
;——————————————————————
accept_16:
read    buf,buf_len

xor     bx,bx
mov     ecx,04
mov     esi,buf
next_digit:
rol    bx,04
mov    al,[esi]
cmp        al,’0′         ; ‘0’ = 30h or 48d
jb         error          ; jump if below ‘0’ to error
cmp        al,’9′
jbe        sub30         ; subtract 30h if no is in the range ‘0’-‘9′

cmp        al,’A’        ; ‘A’ = 41h or 65d
jb         error           ; jump if below ‘A’ to error
cmp        al,’F’
jbe        sub37           ; subtract 37h if no is in the range ‘A’-‘F’

cmp        al,’a’          ; ‘a’ = 61h or 97d
jb         error           ; jump if below ‘a’ to error
cmp        al,’f’
jbe     sub57           ; subtract 57h if no is in the range ‘a’-‘f’

error:  print     emsg,emsg_len    ; “You entered Invalid Data!!!”
exit

sub57:    sub        al,20h          ; subtract 57h if no is in the range ‘a’-‘f’
sub37:  sub        al,07h          ; subtract 37h if no is in the range ‘a’-‘f’
sub30:  sub        al,30h          ; subtract 30h if no is in the range ‘0’-‘9’

add    bx,ax        ; prepare number
inc    esi        ; point to next digit
loop    next_digit
ret

;——————————————————————
display_16:
mov     esi,char_ans+3    ; load last byte address of char_ans in rsi
mov     ecx,4        ; 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_ans,4    ; display result on screen
ret
;—————————————————————-
The steps to run the above program is as follows:

sai@sai-ThinkCentre-A70:~$ nasm -f elf p1.asm
sai@sai-ThinkCentre-A70:~$ ld -m elf_i386 -s -o p1 p1.o
sai@sai-ThinkCentre-A70:~$ ./p1

MIL assignment 01 : Addition of N 16-bit nos.
———————————————
Enter size of array <????> = 0003
Enter data <????>    = 0005
Enter data <????>    = 0002
Enter data <????>    = 0003
Result <????????>    = 0000000A
sai@sai-ThinkCentre-A70:~$

Share Button

Assignment No. 6

Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive addition and add and shift method. Accept input from the user. (use of 64-bit registers is expected)

;——————————p5.asm————————————————
%macro dispmsg 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data

msg db 10,’Enter two digit Number::’
msg_len equ $-msg
res db 10,’Multiplication of elements is::’
res_len equ $-res
choice db 10,13,’Enter your Choice:’
db 10,13,’1.Successive Addition’
db 10,13,’2.Add and Shift method’
db 10,13,’3.Exit’
db 10,13,’Enter choice=’
choice_len equ $-choice

section .bss
num resb 03
num1 resb 01
result resb 04
cho resb 2

section .text

global _start
_start:

mov eax,0
mov ebx,0
mov ecx,0
mov edx,0
mov byte[result],0
mov byte[num],0
mov byte[num1],0

dispmsg choice,choice_len
accept cho,2

cmp byte[cho],31h
je a

cmp byte[cho],32h
je b

jmp exit

a:call Succe_addition

jmp _start

b:call Add_shift

jmp _start

exit:
mov eax,1
int 80h

convert:
mov ebx,0
mov ecx,0
mov eax,0

mov ecx,02
mov esi,num
up1:
rol bl,04
mov al,[esi]
cmp al,39h
jg p1
sub al,30h
jmp p2
p1: sub al,37h
p2:add bl,al
inc esi
loop up1
ret

display:
mov ecx,4
mov edi,result
dup1:
rol bx,4
mov al,bl
and al,0fh
cmp al,09h
jg p3
add al,30h
jmp p4
p3: add al,37h
p4:mov [edi],al
inc edi
loop dup1

dispmsg result,4
ret

Succe_addition:

dispmsg msg,msg_len
accept num,3

call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert
mov ecx,0
mov eax,0
mov eax,[num1]

repet:
add ecx,eax
dec bl
jnz repet

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]

call display
ret

Add_shift:

dispmsg msg,msg_len
accept num,3

call convert
mov [num1],bl

dispmsg msg,msg_len
accept num,3
call convert

mov [num],bl

mov ebx,0
mov ecx,0
mov edx,0
mov eax,0
mov dl,08
mov al,[num1]
mov bl,[num]

p11:shr bx,01
jnc p
add cx,ax
p:shl ax,01
dec dl
jnz p11

mov [result],ecx
dispmsg res,res_len
mov ebx,[result]
call display

ret

;——————————————————————————————————————————
Steps to execute the above program is as follows:

dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ nasm -f elf p5.asm
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ld -m elf_i386 -s -o p5  p5.o
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$ ./p5

Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=1

Enter two digit Number::05

Enter two digit Number::02

Multiplication of elements is::000A
Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=2

Enter two digit Number::05

Enter two digit Number::03

Multiplication of elements is::000F
Enter your Choice:
1.Successive Addition
2.Add and Shift method
3.Exit
Enter choice=3
dhokane@dhokane-ThinkCentre-A70:~/MIT IN LINUX$

Share Button