Skip to content
Related Articles

Related Articles

8086 program to reverse 16 bit number using 8 bit operation
  • Last Updated : 02 Jul, 2018

Problem – Write an assembly language program in 8086 microprocessor to reverse 16 bit number using 8 bit operation.

Example – Assume 16 bit number is stored at memory location 2050 and 2051.

Algorithm –

  1. Load contents of memory location 2050 in register AL
  2. Load contents of memory location 2051 in register AH
  3. Assign 0004 to CX Register Pair
  4. Rotate the contents of AL by executing ROL instruction using CX
  5. Rotate the contents of AH by executing ROL instruction using CX
  6. Store the content of AH in memory location 2050
  7. Store the content of AL in memory location 2051

Program –

Memory AddressMnemonicsComments
400MOV AL, [2050]AL<-[2050]
404MOV AH, [2051]AH<-[2051]
408MOV CX, 0004CX <- 0004
40BROL AL, CXRotate AL content left by 4 bits(value of CX)
40DROL AH, CXRotate AH content left by 4 bits(value of CX)
40FMOV [2050], AH[2050]<-AH
413MOV [2051], AL[2051]<-AL
417HLTStop Execution

Explanation –

  1. MOV AL, [2050]: loads contents of memory location 2050 in AL
  2. MOV AH, [2051]: loads contents of memory location 2051 in AH
  3. MOV CX, 0004: assign 0004 to CX register pair
  4. ROL AL, CX: rotate the content of AL register left by 4 bits i.e. value of CX register pair
  5. ROL AH, CX: rotate the content of AH register left by 4 bits i.e. value of CX register pair
  6. MOV [2050], AH: stores the content of AH in 2050 memory address
  7. MOV [2051], AL: stores the content of AL in 2051 memory address
  8. HLT: stops executing the program
My Personal Notes arrow_drop_up
Recommended Articles
Page :