bc0046 solved

23
BC0046 – Microprocessor 1. Convert the decimal number 321.145 to octal and hexadecimal. Answer: 8 321 8 40 1 8 5 0 0 5 321(10)=501 8 145 8 18 1 8 2 2 0 2 145(10)=221 So,321.145(10)=501.221(8) 16 321 1 20 1

Upload: vipul-desai

Post on 01-Nov-2014

98 views

Category:

Documents


0 download

DESCRIPTION

assignment bc0046

TRANSCRIPT

Page 1: BC0046 Solved

BC0046 – Microprocessor

1. Convert the decimal number 321.145 to octal and hexadecimal.

Answer:

8 321

8 40 1

8 5 0

  0 5

321(10)=501

8 145

8 18 1

8 2 2

  0 2

145(10)=221

So,321.145(10)=501.221(8)

16 321

16 20 1

16 1 4

  0 1

321(10)=

16 145

16 09 1

0 09

 

So,321.145(10)=

Page 2: BC0046 Solved

2. Write an assembly language program to find the smallest among twonumbers.

Answer:

MVI B, 30HMVI C, 40HMOV A, BCMP CJZ EQUJC SMLOUT PORT1HLTEQU: MVI A, 01HOUT PORT1HLTSML: MOV A, COUT PORT1HLTSML: MOV A, COUT PORT1

Page 3: BC0046 Solved

3.Draw and explain the internal architecture of 8085.

Answer:

Page 4: BC0046 Solved

Arithmetic and Logic Unit (ALU):

It is used to perform the arithmetic operations like addition, subtraction, multiplication, division, increment and decrement and logical operations like AND, OR and EX-OR.

It receives the data from accumulator and registers.

According to the result it set or reset the flags.Program Counter (PC):

This 16-bit register sequencing the execution of instructions.

It is a memory pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit register.

The function of the program counter is to point to the memory address of the next instruction to be executed.

When an opcode is being fetched, the program counter is incremented by one to point to the next memory location.

Stack Pointer (Sp):

The stack pointer is also a 16-bit register used as a memory pointer.

It points to a memory location in R/W memory, called the stack.

The beginning of the stack is defined by loading a 16-bit address in the stack pointer (register).

Temporary Register:

Page 5: BC0046 Solved

It is used to hold the data during the arithmetic and logical operations.

Instruction Register: When an instruction is fetched from the memory, it is loaded in the instruction register.

Instruction Decoder: It gets the instruction from the instruction register and decodes the instruction. It identifies the instruction to be performed.

Serial I/O Control: It has two control signals named SID and SOD for serial data transmission.

Page 6: BC0046 Solved

4. Draw and explain the internal architecture of 8086.

Answer: Figure shows the internal architecture of the 8086. Except for theinstruction register, which is actually a 6-byte queue, the control unitand working registers are divided into three groups according to theirfunctions. There is a data group, which is essentially the set ofArithmetic registers; the pointer group, which includes base and indexregisters, but also contains the program counter and stack pointer; andthe segment group, which is a set of special purpose base registers. Allof the registers are 16 bits wide.The data group consists of the AX, BX, CX and DX registers. Theseregisters can be used to store both operands and results and each ofthem can be accessed as a whole, or the upper and lower bytes can beAccessed separately. For example, either the 2 bytes in BX can be usedTogether, or the upper byte BH or the lower byte BL can be used byitself by specifying BH or BL, respectively. registers play special addressing, counting, and I/O roles:BX may be used as a base register in address calculations.CX is used as an implied counter by certain instructions.DX is used to hold the I/O address during certain I/O operations.The pointer and index group consists of the IP, SP, BP, SI, and DIregisters. The instruction pointer IP and SP registers are essentially theprogram counter and stack pointer registers, but the completeinstruction and stack addresses are formed by adding the contents ofthese registers to the contents of the code segment (CS) and stacksegment (SS) registers. BP is a base register for accessing the stackand may be used with other registers and/or a displacement that ispart of the instruction. The SI and DI registers are for indexing.Although they may be used by themselves, they are often used withthe BX or BP registers and/or a displacement. Except for the IP, apointer can be used to hold an operand, but must be accessed as awhole.To provide flexible base addressing and indexing, a data address maybe formed by adding together a combination of the BX or BP registercontents, SI or DI register contents, and a displacement. The result ofsuch an address computation is called an effective address (EA) oroffset. The word “displacement” is used to indicate a quantity that is

Page 7: BC0046 Solved

added to the contents ‘of a register(s) to form an EA. The final dataaddress, however, is determined by the EA and the appropriate datasegment (DS), extra segment (ES), or stack segment (SS) register.The segment group consists of the CS, SS, DS, and ES registers. Asindicated above, the registers that can be used for addressing, the BX,

Page 8: BC0046 Solved

5. Write a sequence of instructions to reverse a two digit hexadecimalnumber available in the register AX using shift and rotate instructions

Answer: Shift and rotate instructionsThe shift and rotate instructions for the 8086 are defined in Fig. 5.These instructions shift all of the bits in the operand to the left or rightby the specified count, CNT. For the shift left instructions, zeroes areshifted into the right end of the operand and the MSBs are shifted outthe left end and lost, except that the least significant bit of these MSBsis retained in the CF flag. The shift right instructions similarly shift bitsto the right; however, SAR (shift arithmetic right) does notautomatically insert zeroes from the left; it extends the sign of theoperand by repeatedly inserting the MSB. The rotate instructions differfrom theshift instructions in that the operand is treated like a circle in which thebits shifted out of one end are shifted into the other end. The RCL andRCR instructions include the carry flag in the circle and the ROL andROR do not, although the carry flag is affected in all cases

Page 9: BC0046 Solved

6. Explain the concept of Linking and Relocation.

Answer: In constructing a program some program modules may be put in the same source module and assembles together; others may be in different source modules and assembled separately. If they are assembled separately ,then the main module, Which has the first instruction to be executed ,must be terminated by an END statement with the entry point specified, and each of the other modules must be terminated by an END with no operand. In any event, the resulting object modules, some of which may be grouped into libraries, must be linked together to form a load module before the program can be executed. In addition to outputting the load module normally the linker prints a memory map that indicates where the linked object modules will be loaded into memory. After the load module has been created it is loaded into memory of the computer by the loader and execution begins. Although the I/O can be performed by modules within the program, normally the I/O is done by I/O drivers that are part of the program, normally the I/O is done by I/O drivers that are part of the operating system. All that appears in the user’s program are references to the I/O drivers that cause the operating system to execute them.

Page 10: BC0046 Solved

Question7: Differentiate macros and procedures

Answer:

ProceduresMacros

A procedure is a set of code that can be branched to and returned from in such a way that code is as is it were inserted at the point from it is branched.

There is a sequential execution in the case of procedure

procedure is faster as there is sequential execution. 

While defining procedure if we use stack explicitly we have to define stack segment.

While defining procedure if we use stack explicitly we have to define stack segment.

A macro is a segment of code that needs to be written only once but whose basic structure can be caused to be repeated several times within a source module by placing a single statement at the point of each appearance.

Macro is comparatively slower as there is branched execution

procedure is faster as there is sequential execution. 

In the case of macro we have to write include (file name).macro before the data segment or code segment (if in some case data segment is absent).

Page 11: BC0046 Solved
Page 12: BC0046 Solved

Question8:What is the operational difference between the IRET and RETinstructions?

Answer: It is sometimes necessary to have the computer automaticallyexecute one of a collection of special routines whenever certainconditions exist within a program or the computer system. The actionthat prompts the execution of one of these routines is called aninterrupt and the routine that is executed is called an interrupt routine.There are two general classes of interrupts and associated routines.There are the internal interrupts that are initiated by the state of theCPU or by an instruction, and the external interrupts that are causedby a signal being sent to the CPU from elsewhere in the computersystem. Typical internal interrupts are those caused by a division byzero or a special instruction and typical external interrupts are causedby the need of an I/O device to be serviced by the CPU.An interrupt routine is similar to a procedure in that it may bebranched to from any other program and a return branch is made tothat program after theinterrupt routine has executed. The interrupt routine must be writtenso that, except for the lapse in time, the interrupted program willproceed just as if nothing had happened. This means that the PSW andthe registers used by the routine must be saved and restored and thereturn must be made to the instruction following the last instructionexecuted before the interrupt. An interrupt routine is unlike aprocedure in that, instead of being linked to a particular-program, it issometimes put in a fixed place (absolutely located) in memory.Because it is not linked to other segments, it can use only commonareas that are absolutely located to communicate with other programs.

Because some kinds of interrupts -are initiated by external events,they occur at random points in the interrupted program. For suchinterrupts, no parameters or parameter addresses can be passed tothe interrupt routine. Instead, data communication must be madethrough variables that are directly accessible by both routines.Regardless of the type of interrupt, the actions that result from aninterrupt are the same and are known as the interrupt sequence. Theinterrupt sequence for the 8086 is shown in Fig. 5.8. Some kinds ofinterrupts are controlled by the IF and TF flags and in those casesthese flags must be properly set or the interrupt action is blocked. Ifthe conditions for an interrupt are met and the necessary flags are set,

Page 13: BC0046 Solved

the instruction that is currently executing is completed and theinterrupt sequence proceeds by pushing the current contents of thePSW, CS, and IP onto the stack, inputting the new contents of IP and CSfrom a double word whose address is determined by the type ofinterrupt, and clearing the If and TF flags. The new contents of the IPand CS determine the beginning address of the interrupt routine to beexecuted. After the interrupt has been executed the return is made tothe interrupted program by an instruction that pops the IP, CS, andPSW from the stack.

9. Describe about each flag of a 8086 flag register.

Answer: The 8086’s PSW contains 16 bits, but 7 of them are not used.Each bit in the PSW is called a flag. The 8086 flags are divided into theconditional flags, which reflect the result of the previous operationinvolving the ALU, and the control flags, which control the execution ofspecial functions. The flags are summarized in Fig. 9The condition flags are:SF (Sign FIag)-Is equal to the MSB of the result. Since in 2’scomplement negative numbers have a 1 in the MSB and fornonnegative numbers this bit is 0, this flag indicates whether theprevious result was negative’ or nonnegative.ZF (Zero Flag)-Is set to 1 if the result is zero and 0 if the result isnonzero.

PF (Parity Flag)-Is set to 1 if the low-order 8 bits of the resultcontains an even number of 1’s; otherwise it is cleared.CF (Carry Flag)-An addition causes this flag to be set if there is acarry out of the MSB, and a subtraction causes it to be set if a borrowis needed. Other instructions also affect this flag and its value will bediscussed when these instructions are defined.AF (Auxiliary Carry Flag)-Is set if there is a carry out of bit 3 duringan addition or a borrow by bit 3 during a subtraction. This flag is usedexclusively for BCD arithmetic.OF (Overflow Flag)-Is set if an overflow occurs, i.e., a result is out ofrange. More specifically, for addition this flag is set when there is a

Page 14: BC0046 Solved

carry into the MSB and no carry out of the MSB or vice versa. Forsubtraction, it is set when the MSB needs a borrow and there is noborrow from the MSB or vice versa. As an example, if the previousinstruction performed the addition0010 0011 0100 1101+ 0011 0010 0001 00010101 0101 0101 1110then following the instruction:SF=0 ZF=0 PF=0 CF=0 AF=0 OF=0

the string is processed from its beginning with the first element havingthe lowest address. Otherwise, the string is processed from the highaddress towards the low address.IF (Interrupt Enable Flag)-Ifset, a certain type of interrupt (a maskable interrupt) can berecognized by the CPU; otherwise, these interrupts are ignored.TF (Trap Flag)-Ifset, a trap is executed after each instruction.

Page 15: BC0046 Solved

10. Write an assembly program to add and display two numbers.

Answer: To add two 16-bit numbers

;PROGRAM TO ADD TWO 16 – BIT DATADATA SEGMENT ;Assembler directiveORG 1100H ; Assembler directiveDATA1 DW 0 ; Assembler directiveDATA 2 DW 0 ; Assembler directiveSUM DW 0 ; Assembler directiveCARRY 0 ; Assembler directiveDATA ENDSCODE SEGMENTASSUME CS : CODE ; Assembler directiveASSUME DS: DATA ; Assembler directiveORG 1000 H ; Assembler directiveMOV AX, DATA1 ; Load the first data in AX registerMOV CL, 00H ; Clear the CL register forcarryADD AX, DATA2 ;Add 2nd data to AX, sum will be inAXMOV SUM, AX ;Store sum in memorylocation (1104H)JNC AHEAD ;Check the status of carry flagINC CL ;If carry is set, increment CLby oneAHEAD: MOV CARRY, CL ;Store carry in memory location(1106H)HLTCODE ENDS :Assembler directiveEND ;Assembler directive

Page 16: BC0046 Solved