Discover 1’s complement of a quantity
Algorithm for locating 1’s Complement
Step I : Initialize the information reminiscence.
Step II : Load the quantity in AX.
Step III : Initialize counter = 16.
Step IV : Rotate quantity by 1 bit place to left with carry.
Step V : Complement carry.
Step VI : Decrement counter.
Step VII : Test if rely = 0. If sure, go to step VIII else goto Step IV.
Step VIII : Rotate quantity by 1 bit place to left with carry to revive unique carry again.
Step IX : Show 1’s complement.
Step X : Cease.
Program Code 1’s complement of a quantity:
1 |
.mannequin small<br/><br/>.information<br/><br/>a dw 1234H<br/><br/>.code<br/><br/>mov ax, @information ; Initialize information part<br/><br/>mov ds, ax<br/><br/>mov ax, a ; Load number1 in ax<br/><br/>mov cx, 16 ; Load CX with rely<br/><br/>up : rcl ax, 1 ; Rotate ax by 1bit to left with carry<br/><br/>cmc ; discover 1's complement of bit<br/><br/>loop up ; test if all bits complemented, if not goto up<br/><br/>rcl ax, 1 ; return carry again to unique place<br/><br/>mov ch, 04h ; Rely of digits to be displayed<br/><br/>mov cl, 04h ; Rely to roll by 4 bits<br/><br/>mov bx, ax ; Lead to reg bx<br/><br/>l2: rol bx, cl ; roll bl in order that msb involves lsb<br/><br/>mov dl, bl ; load dl with information to be displayed<br/><br/>and dl, 0fH ; get solely lsb<br/><br/>cmp dl, 09 ; test if digit is 0-9 or letter A-F<br/><br/>jbe l4<br/><br/>add dl, 07 ; if letter add 37H else solely add 30H<br/><br/>l4: add dl, 30H<br/><br/>mov ah, 02 ; Perform 2 below INT 21H<br/><br/>; (Show character)<br/><br/>int 21H<br/><br/>dec ch ; Decrement Rely<br/><br/>jnz l2<br/><br/>mov ah, 4cH ; Terminate Program<br/><br/>int 21H<br/><br/>finish |
Supply projectgeek.com