Wednesday, 7 September 2016

rotateNibble Subroutine in Assembly Language

rotateNibble Subroutine in Assembly Language

Description: Consider blocks of data as shown in following array:

      0x1f5c, 0xfffa, 0xcc2a, 0xaaa9  

In the following Assembly Language 8086 programming example, a routine named rotateNibble is written that takes the data array and its size as input parameters and pushes the least significant nibble of all elements in the array in a clockwise manner as shown below:

      0xc1f5, 0xafff, 0xacc2a, 0x9aaa

[org 0x0100]

   jmp main

   push bp
   mov bp , sp
   push ax
   push bx
   push cx
   push si
   mov bx , [bp+6]                 ;BX=address of the data
   mov cx , [bp+4]                 ;CX=size of the data
   mov si , 0
      mov ax , [bx+si]             ;AX= an element from data
      ror ax , 4                   ;rotates it 4 times
      mov [bx+si] , ax             ;store the result back to data
      add si , 2                   ;point SI to the next element of data
      loop rotate
   pop si
   pop cx
   pop bx
   pop ax
   pop bp
   ret 4           ;return empty stack
   mov bx , data
   push bx
   mov ax , [size]
   push ax
   call rotateNibble
   mov ax , 0x4c00
   int 0x21

size: dw 6

data: dw 0x1f5c, 0xfffa, 0xcc2a, 0xaaa9,0x1234,0x0110

No comments

Post a Comment

Recent Posts