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$

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$

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$

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$

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$

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$

1. Microprocessor and Interfacing Techniques SE Computer Engineering April/May 2014

Q.1 (a) What are the different component of MS-DOS? Explain DOS loading with the help of neat diagram

Ans:

MS-DOS is created using following three files.

IO.SYS,

MSDOS.SYS,

COMMAND.COM,

AUTOEXE.BAT.
These files are created for special purpose like  creating, booting and coordinating with devices for input, output  and saving internal commands of DOS in memory.In other words these are program files which are created which creating DOS.

IO.SYS: These two files are hidden files. These are system files and are present on every disc. At the time of booting both of these Files are automatically get saved in Temporary Memory. IO.sys stores the standard operation related to input and output devices. And MSDOS.sys file stores command that contact with operating system.

COMMAND.COM :This is a command interpreter file in MS-DOS which is a group of IO.sys, MSDOS.sys and COMMAND.COM. At the time of booting of computer, all these three files are automatically saved in the memory. COMMAND.COM file contains all the definitions of Internal command and programs of these commands. This file is mainly responsible for executing command which are typed by user in command prompt.

AUTOEXE.BAT: After booting Operating System it looks for AUTOEXE.BAT file in the disc and executes it. This process is repeated when computer is switched on. It is a batch file which contains MS-DOS command like a program file and it automatically executes the command written in it. Therefore it is named AUTOEXE.BAT which means self executable batch file. BIOS is a set of basic instructions and drivers for the monitor, keyboard, printer, I / O ports and other devices in the PC configurations. The task of the BIOS is to mediate between the demands of the remaining parts of the OS and all of these devices. BIOS each OS translates the request into a series of instructions that the microprocessor controlled devices. Many manufacturers expand content BIOS variety of additional features, such as antivirus software, since current technology allows, but for correct operation must not disturb the base that must be the same as the IBM BIOS. When the BIOS enables the microprocessor to make contact with the disk (partition) on which the operating system, the command for copying files to the following picture.

New Bitmap Image (5)

MSDOS.SYS and IO.SYS form the CORE of the operating system. Group DBLSPACE.??? used when the data is compressed on disk. COMMAND.COM is INTERPRETER (simultaneous interpreter) command, which the user specified via the keyboard, and forwards them to the core operating system for execution. This practically means that the user does not have to be a direct relationship with the core OS. Listed files represent monitor OS. The computer can not work if one of them is damaged or missing. If it does not use data compression DBLSPACE.??? group of files is not necessary.

COMMAND.COM file called the command processor and next to these tasks contains over 30 short of the necessary gadgets to perform everyday tasks. These gadgets are invited to perform by typing their names (KEYWORD) and possibly supplement and represent commands and orders the OS. The commands are executed immediately, and orders delayed because they seek more answers to queries. How are constantly working memory are said to be INTERNAL.

Q.1 (b)  Compare 8086, 80386 and i7 processor on the basis of architectural features.

Sr. No

8086

8087

I7

1.The instruction Queue is 6 byte long.It is a 32 bit microprocessor and it is logical extension of the 80236.64 bit
2.In 8086 memory divides into two banks, up to 1,048,576 bytesIt is highly pipelined architecture and much faster speed bus than 8086.32/64 bit Address bus
3.The data bus of 8086 is 16-bit wideHowever, 80386 can support 8086 programming model & can also directly run the programs  written for 8086 in virtual mode if VM=1(in protected mode)64 GB Physical Memory
4.It has BHE# signal on pin no. 34 & there is no SSO# signal.The chip of 80836 contains 132 pins.64 bit register size
5.The output signal is used to select memory or I/O at M/IO# but if IO#/M low or logic ‘0’ it selects I/O devices and if IO#/M is high or logic ‘1’it selects memory.The 80386 using High-speed CHMOS III technology.1366 pin architecture
6.It needs one machine cycle to R/W signal if it is at even location otherwise it needs two.It has a special hardware for task switching.It support 8086 + 80386 + SIMD

instructions

7.In 8086, all address & data Buses are multiplexed.The 80386 operate 33MHz clock frequency maximum.L1: 32KB instruction cache +32 KB data cache

L2: 256 KB for each core

L3: 8 MB shared by all four cores

8.It needs two IC 74343 for de-multiplexing AD0-AD19.It has separate address and data bus for time saving.Hyper Threading

Support

9. Transistor density and complexity further increases 2,75,00018 Bytes instruction cache
10. It has total 129 instructions6 (16 bit) segment registers
11. The 80386  contains protection mechanism paging which has instruction two support them

GDTR: 80 bits

IDTR: 80 bits

LDTR: 16 bits

TR: 16 bits

Selector: 16 bits

Limit: 32 bits

Base: 64 bits

12. It operate in three modes
a)Real
b)Virtual
c)Protected

1. Smart Cache

2. Virtualization Technology

3. Turbo Boost Technology

13. It has instruction Queue as well as pre fetch queue. 
14. It contains all nine flags of 8086 but other flags named IOP,NT,RF,VM 
15. GDTR: 48 bits

IDTR: 48 bits

LDTR: 16 bits

TR: 16 bits

Selector: 16 bits

Limit: 16 bits

Base: 32 bits

 

Q.2 (a) Draw and explain block diagram of 8259APIC.

Ans: The 8259A is designed to minimize the software and real time overhead in handling multilevel priority interrupts It has several modes permitting optimization for a variety of system requirements.

8259

  1. Vcc: SUPPLY  +5V Supply
  2. GND: Ground
  3. CS#: CHIP SELECT A low on this pin enables RD and WR communication between the CPU and the 8259A INTA functions are independent of CS.
  4. WR#: WRITE A low on this pin when CS is low enables the 8259A to accept
    command words from the CPU.
  5. RD#: READ A low on this pin when CS is low enables the 8259A to release
    status onto the data bus for the CPU.
  6. D7-D0: BIDIRECTIONAL DATA BUS Control status and interrupt-vector
    information is transferred via this bus.
  7. CAS0 –CAS2: CASCADE LINES The CAS lines form a private 8259A bus to control a multiple 8259A structure These pins are outputs for a master 8259A and inputs for a slave 8259A
  8. SP#/EN#:SLAVE PROGRAM ENABLE BUFFER This is a dual function pin
    When in the Buffered Mode it can be used as an output to control
    buffer transceivers (EN) When not in the buffered mode it is used as
    an input to designate a master (SP=1) or slave (SP=0).
  9. INT: INTERRUPT This pin goes high whenever a valid interrupt request is
    asserted It is used to interrupt the CPU thus it is connected to the
    CPU’s interrupt pin.
  10. IR0 –IR7: NTERRUPT REQUESTS Asynchronous inputs An interrupt request
    is executed by raising an IR input (low to high) and holding it high until
    it is acknowledged (Edge Triggered Mode) or just by a high level on an
    IR input (Level Triggered Mode).
  11. INTA#: INTERRUPT ACKNOWLEDGE This pin is used to enable 8259A
    interrupt-vector data onto the data bus by a sequence of interrupt
    acknowledge pulses issued by the CPU.
  12. A0: AO ADDRESS LINE This pin acts in conjunction with the CS WR and RD pins It is used by the 8259A to decipher various Command Words the CPU writes and status the CPU wishes to read It is typically connected to the CPU A0 address line (A1 for 8086 8088).

Q.2 (b) Write the initialization instructions of 8259A PIC, to meet the following specifications :
(i) Interrupt type 32.

(ii) Edge Triggered, single and ICW4 needed, interval of 8.

(iii) Mask IR1 & IR3 interrupts.

Ans:

(i) Interrupt type 32 : On the PC, the BIOS (and thus also DOS) traditionally maps the master 8259 interrupt requests (IRQ0-IRQ7) to interrupt vector offset 8 (INT08-INT0F) and the slave 8259 (in PC/AT and later) interrupt requests (IRQ8-IRQ15) to interrupt vector offset 112 (INT70-INT77). This was done despite the first 32 (INT00-INT1F) interrupt vectors being reserved by the processor for internal exceptions (this was ignored for the design of the PC for some reason). Because of the reserved vectors for exceptions most other operating systems map (at least the master) 8259 IRQs (if used on a platform) to another interrupt vector base offset.

(ii) Edge Triggered, single and ICW4 needed, interval of 8:

SFNM: SFNM=1 the special fully nested mode is programmed

BUF: If BUF=1 the buffered mode is programmed In buffered mode SP#/EN# becomes an enable output and the master/slave determination is by M/S

M/S: If buffered mode is selected M/S=1 means the 8259A is programmed to be a master, M/S=0 means the 8259A is programmed to be a slave If BUF =0, M/S has no function

AEOI: If AEOI=1 the automatic end of interrupt mode is programmed.

Microprocessor mode: mPM=0 sets the 8259A for MCS-80, 85 system operation, mPM =1 sets the 8259A for 8086 system operation.

(iii) Mask IR1 & IR3 interrupts: Each Interrupt Request input can bem masked individually by the Interrupt Mask Register (IMR) programmed through OCW1 Each bit in the IMR masks one interrupt channel if it is set (1) Bit 0 masks IR0 Bit 1 masks IR1 and so forth Masking an IR channel does not affect the other channels operation

Q. 3 (a) Draw and explain I/O of BSR mode of 8255 with appropriate
control word formats.

Ans:

BSR Mode: In this mode any of the 8-bits of port C can be set or reset depending on D0 (if D0=1 then SET, D0=0 then RESET) of the control word. The bit to be set or reset is selected by bit select flags D3, D2 and D1 of the CWR as given in table.

BSR Mode : CWR Format

D3D2D1Selected bits of port C
000D0
001D1
010D2
011D3
100D4
101D5
110D6
111D7

 Fig 1.9

Q.3 (b) Draw and discuss internal block diagram of 8251 USART.

Ans:

The functional block diagram of 825 1A consists five sections. They are:
  1. Read/Write control logic
  2. Transmitter
  3. Receiver
  4. Data bus buffer
  5. Modem control.
 
The functional block diagram is shown in fig:

BD-8251-pic2(59)

1. Read/Write control logic:The Read/Write Control logic interfaces the 8251A with CPU, determines the functions of the 8251A according to the control word written into its control register. It monitors the data flow. This section has three registers and they are control register, status register and data buffer. The active low signals RD, WR, CS and C/D(Low) are used for read/write operations with these three registers. When C/D(low) is high, the control register is selected for writing control word or reading status word. When C/D(low) is low, the data buffer is selected for read/write operation. When the reset is high, it forces 8251A into the idle mode. The clock input is necessary for 8251A for communication with CPU and this clock does not control either the serial transmission or the reception rate.

2. Transmitter section: The transmitter section accepts parallel data from CPU and converts them into serial data. The transmitter section is double buffered, i.e., it has a buffer register to hold an 8-bit parallel data and another register called output register to convert the parallel data into serial bits. When output register is empty, the data is transferred from buffer to output register. Now the processor can again load another data in buffer register. If buffer register is empty, then TxRDY is goes to high. If output register is empty then TxEMPTY goes to high. The clock signal, TxC (low) controls the rate at which the bits are transmitted by the USART. The clock frequency can be 1,16 or 64 times the baud rate.

3. Receiver Section:The receiver section accepts serial data and convert them into parallel data. The receiver section is double buffered, i.e., it has an input register to receive serial data and convert to parallel, and a buffer register to hold the parallel data.When the RxD line goes low, the control logic assumes it as a START bit, waits for half a bit time and samples the line again. If the line is still low, then the input register accepts the following bits, forms a character and loads it into the buffer register. The CPU reads the parallel data from the buffer register.When the input register loads a parallel data to buffer register, the RxRDY line goes high. The clock signal RxC (low) controls the rate at which bits are received by the USART. During asynchronous mode, the signal SYNDET/BRKDET will indicate the break in the data transmission. During synchronous mode, the signal SYNDET/BRKDET will indicate the reception of synchronous character.

4. Data bus buffer: Data bus buffer is used to communicate with the system data bus. The data bus is D0-D7.

5. MODEM Control: The MODEM control unit allows to interface a MODEM to 8251A and to establish data communication through MODEM over telephone lines.

NEXT POSTblafibutton

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:\>

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

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$