Search This Blog

Tuesday, February 11, 2014

Program to find out Lenght of String in 8086 assembly language

DATA SEGMENT   
        MSG1 DB 10,13,'ENTER String :$'
        MSG2 DB 10,13,'Lenght of string is : $'
        MSG3 DB 10,13,'Reverse of String is : $'
        MSG4 DB 10,13,'Concated String is :$'
        str1 db 10 dup(0)
        str2 db 10 dup(0)
DATA ENDS

CODE SEGMENT
        ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX
       
        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str1
       
 BACK:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back


     ; code to find out lenght
      mov ch,00h
      Mov si, offset str1
 next:
      inc ch
      mov al,[si]
      inc si
      cmp al,'$'    
      jnz next

      add ch,'0'

      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG2
      INT 21H

      mov ah, 2
      mov dl, ch
      int 21h

      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END




Assembly Language Program for String Manipulation in 8086 assembly language

DATA SEGMENT   
        MSG1 DB 10,13,'ENTER String :$'
        MSG2 DB 10,13,'Lenght of string is : $'
        MSG3 DB 10,13,'Reverse of String is : $'
        MSG4 DB 10,13,'Concated String is :$'
        str1 db 10 dup(0)
        str2 db 10 dup(0)
DATA ENDS

CODE SEGMENT
        ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX
       
        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str1
       
 BACK:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back

        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str2
       
 BACK1:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back1


        Mov si, offset str1
 next:
      mov al,[si]
      inc si
      cmp al,'$'    
      jnz next               
     
     DEC si
     
     
      Mov di, offset str2
backward:
      mov al,[di]  
      mov [si],al
      inc si
      inc di
      cmp al,'$'
      jnz backward

          
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG4
      INT 21H
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,str1
      INT 21H



      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END




Assembly Language Program for String Manipulation in 8086 assembly language

DATA SEGMENT   
        MSG1 DB 10,13,'ENTER String :$'
        MSG2 DB 10,13,'Lenght of string is : $'
        MSG3 DB 10,13,'Reverse of String is : $'
        MSG4 DB 10,13,'Concated String is :$'
        str1 db 10 dup(0)
        str2 db 10 dup(0)
DATA ENDS

CODE SEGMENT
        ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX
       
        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str1
       
 BACK:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back


     ; code to find out lenght
      mov ch,00h
      Mov si, offset str1
 next:
      inc ch
      mov al,[si]
      inc si
      cmp al,'$'    
      jnz next

      DEC si
      dec si
      dec ch
      Mov di, offset str2
backward:
      mov al,[si]  
      mov [di],al
      dec si
      inc di
      dec ch
      jnz backward
      mov al,'$'
      mov [di],al
     
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG3
      INT 21H
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,str2
      INT 21H

      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END

Thursday, January 24, 2013

Assignment on 80386 from prevoius year papers with answers


Assignment No 1 [with minimum answer]

[Should be submitted in separate homework notebook of 100 pages by 31st January, 2013]

1.      What is Machine Status Word (MSW) of 80386? Draw its format.
Ans:
  Figure : Control Register 0 ( Machine Status Word ) of 80386

PG (Paging Enable, bit 31)
The PG bit is set to enable the on-chip paging unit. It is reset to disable the on-chip paging unit.
R (reserved, bit 4)
This bit is reserved by Intel. When loading CR0 care should be taken to not alter the value of this bit.
TS (Task Switched, bit 3)
TS is automatically set whenever a task switch operation is performed. If TS is set, a coprocessor ESCape opcode will cause a Coprocessor Not Available trap (exception 7). The trap handler typically saves the Intel387 DX coprocessor context belonging to a previous task, loads the Intel387 DX coprocessor state belonging to the current task, and clears the TS bit before returning to the faulting coprocessor opcode.
EM (Emulate Coprocessor, bit 2)
The EMulate coprocessor bit is set to cause all coprocessor opcodes to generate a Coprocessor Not Available fault (exception 7). It is reset to allow coprocessor opcodes to be executed on an actual Intel387 DX coprocessor. Note that theWAIT opcode is not affected by the EM bit setting.
MP (Monitor Coprocessor, bit 1)
The MP bit is used in conjunction with the TS bit to determine if the WAIT opcode will generate a Coprocessor Not Available fault (exception 7) when TS e 1. When both MP e 1 and TS e 1, the WAIT opcode generates a trap. Otherwise, the WAIT opcode does not generate a trap. Note that TS is automatically set whenever a task switch operation is performed.
PE (Protection Enable, bit 0)
The PE bit is set to enable the Protected Mode. If PE is reset, the processor operates again in Real Mode. PE may be set by loading MSW or CR0. PE can be reset only by a load into CR0. Resetting the PE bit is typically part of a longer instruction sequence needed for proper transition from Protected Mode to Real Mode.
2.   With the help of block diagram explain the architecture of 80386.
Ans:

Figure : 80386 Architecture block Diagram
 
 [Explanation should include around one sentence about each block in above figure.]


3.      What is the function of BE0 to BE3 signal in 80386?
                        Ans:
The 386 address bus consists of the A2-A31 address lines and the byte enable lines BE0# - BE3#.  The BE0#-BE3# lines are decoded from internal address signals A0 and A1 and function very similarly to the way A0 and BHE function in an 8086 or 80286 system.  The 80386 has a 32-bit data bus, so memory can be set up as four byte-wide banks.  The BE0# - BE3# signals function as enables for the four banks.  These individual enables allow the 386 to transfer bytes, words, or double words to and from memory.  Incidentally, the # symbol after the BE signal names indicates that these signals are active low.
[Draw table of mapping A0, A1 with this lines]
4.            Explain BIU of 80386.
Ans:
[Draw part of architecture corresponding to Bus Interface.]
[Explain all pins connected to BIU.]
5.            Explain interrupt pins of 80386.
Ans:
 1. INTR:  INTERRUPT REQUEST is a maskable input that signals the 80386 to suspend execution of the current program and execute an interrupt acknowledge function.
2. NMI: NON-MASKABLE INTERRUPT REQUEST is a non-maskable input that signals the 80386 to suspend execution of the current program and execute an interrupt acknowledge function.
3. RESET:  RESET suspends any operation in progress and places the 80386 in a known reset state. See Interrupt Signals for additional information.

6.      Explain debug registers in 80386.
Ans:
The six programmer accessible debug registers provide on-chip support for debugging.  Debug Registers DR0- specify the four linear breakpoints. The Debug Control Register DR7 is used to set the breakpoints and the Debug Status Register DR6, displays the current state of the breakpoints.

7.      Explain Difference between 8086 and 80386.
Ans:
[Find out at least 8 points]

Tuesday, January 22, 2013

Flag Register of 80386 micro processor



Flag Register of 80386

  [ source: Intel386 DX Manual]


Note in these descriptions, ``set'' means ``set to 1,'' and ``reset'' means ``reset to 0.''


 VM (Virtual 8086 Mode, bit 17)

The VM bit provides Virtual 8086 Mode within Protected Mode. If set while the 80386 is in Protected Mode, the 80386 will switch to Virtual 8086 operation, handling segment loads as the 8086 does, but generating exception 13 faults on privileged opcodes.

RF (Resume Flag, bit 16)

The RF flag is used in conjunction with the debug register breakpoints. It is checked at instruction boundaries before breakpoint processing. When RF is set, it causes any debug fault to be ignored on the next instruction. RF is then automatically reset at the successful completion of every instruction.

NT (Nested Task, bit 14)

This flag applies to Protected Mode. NT is set to indicate that the execution of this task is nested within another task. If set, it indicates that the current nested task's Task State Segment (TSS) has a valid back link to the previous task's TSS. This bit is set or reset by control transfers to other tasks.

IOPL (Input/Output Privilege Level, bits 12-13)

This two-bit field applies to Protected Mode. IOPL indicates the numerically maximum CPL (current privilege level) value permitted to execute I/O instructions without generating an exception 13 fault or consulting the I/O Permission Bitmap. It also indicates the maximum CPL value allowing alteration of the IF (INTR Enable Flag) bit when new values are popped into the EFLAG register.

OF (Overflow Flag, bit 11)

OF is set if the operation resulted in a signed overflow. Signed overflow occurs when the operation resulted in carry/borrow into the sign bit (high-order bit) of the result but did not result in a carry/borrow out of the high order bit, or vice-versa. For 8/16/32 bit operations, OF is set according to overflow at bit 7/15/31, respectively.

DF (Direction Flag, bit 10)

DF defines whether ESI and/or EDI registers post decrement or post increment during the string instructions. Post increment occurs if DF is reset. Post decrement occurs if DF is set.

IF (INTR Enable Flag, bit 9)

The IF flag, when set, allows recognition of external interrupts signaled on the INTR pin.
When IF is reset, external interrupts signaled on the INTR are not recognized. IOPL indicates the maximum CPL value allowing alteration of the IF bit when new values are popped into EFLAGS or FLAGS.

TF (Trap Enable Flag, bit 8)

TF controls the generation of exception 1trap when single-stepping through code. When TF is set, the 80386 generates an exception 1 trap after the next instruction is executed. When TF is reset, exception 1 traps occur only as a function of the breakpoint addresses loaded into debug registers DR0±DR3.

SF (Sign Flag, bit 7)

SF is set if the high-order bit of the result is set, it is reset otherwise. For 8-, 16-, 32-bit operations, SF reflects the state of bit 7, 15, 31 respectively.

ZF (Zero Flag, bit 6)

ZF is set if all bits of the result are 0. Otherwise it is reset.

AF (Auxiliary Carry Flag, bit 4)

The Auxiliary Flag is used to simplify the addition and subtraction of packed BCD quantities. AF is set if the operation resulted in a carry out of bit 3 (addition) or a borrow into bit 3 (subtraction). Otherwise AF is reset. AF is affected by carry out of, or borrow into bit 3 only, regardless of overall operand length: 8, 16 or 32 bits.

PF (Parity Flags, bit 2)

PF is set if the low-order eight bits of the operation contains an even number of ``1's'' (even parity). PF is reset if the low-order eight bits have odd parity. PF is a function of only the low-order eight bits, regardless of operand size.

CF (Carry Flag, bit 0)

CF is set if the operation resulted in a carry out of (addition), or a borrow into (subtraction) the high-order bit. Otherwise CF is reset. For 8-, 16- or 32-bit operations, CF is set according to carry/borrow at bit 7, 15 or 31, respectively.


Thursday, January 10, 2013

Read number from user in assembly language of 8086


;Read number from user in assembly language of 8086

DATA SEGMENT
          FIRST DB 00H
DATA ENDS
CODE SEGMENT
    ASSUME CS:CODE, DS:DATA
 START:
      MOV AX, DATA
      MOV DS, AX
READMORE:
      MOV AH,01H
      INT 21H
      CMP AL,'0'
      JB NOMOREREAD
      CMP AL, '9'
      JA NOMOREREAD
      MOV BL,AL
      MOV AH,10
      MUL FIRST
      SUB BL,30H
      ADD AH, BL
      MOV FIRST, AH
      JMP READMORE
 NOMOREREAD:
      ; THIS IS TO TERMINATE AND GIVE CONTROL TO DOS
      MOV AH, 4CH
      INT 21H

CODE ENDS
 END START

Monday, January 7, 2013

Program to find out factorial of number in 8086 assembly language

;Program to find out factorial of number in 8086 assembly language

data segment
     number dw 04h
ends

stack segment
    dw   128  dup(0)
ends

code segment
    assume cs:code, ds:data
start:
    ; set segment registers:
    mov ax, data
    mov ds, ax
 
    mov cx,number
    call fact         
    mov ax, 4c00h ; exit to operating system.
    int 21h 
   
    ;procedure for factorial program
    ;assume cx contains input number
    ;assume Dx contains result 
    fact proc near
           cmp cx, 01h
           jne cont
           mov dx,01h
           ret
  cont:    push cx ; for backup
           dec cx  
           call fact 
           pop ax    ; backup of cx ie n
           mul dx    ; n*(n-1)!
           mov dx, ax ; result into dx
           ret                                          
    fact endp
ends

end start ; set entry point and stop the assembler.