Advertisement
lukicdarkoo

Parni Paritet

Apr 22nd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #void SetParity(word *vrijednost);
  2. .section .text
  3. .globl SetParity
  4.  
  5.  
  6. SetParity:
  7.     pushl %ebp
  8.     movl %esp, %ebp
  9.  
  10.     movl 8(%esp), %eax
  11.     movw (%eax), %ax    # %ax broj
  12.    
  13.  
  14.     movb $0, %dl    #paran/neparan
  15.     movw $1, %cx    #maska
  16.     movl $0, %esi   #brojac
  17.     while:
  18.     cmpl $15, %esi
  19.     je whileKraj
  20.         testw %cx, %ax
  21.         jz whileBrojac
  22.  
  23.         # %dl ce za parni ce biti 0, za neparni 1
  24.         xorb $1, %dl
  25.        
  26.         whileBrojac:
  27.         incl %esi
  28.         shlw $1, %cx
  29.     jmp while
  30.     whileKraj:
  31.  
  32.     cmpb $0, %dl
  33.     je kraj
  34.  
  35.  
  36.     #e sad, ako je neparan negiram prvi bit
  37.     movw $1, %cx
  38.     shlw $15, %cx
  39.     xorw %cx, %ax
  40.  
  41.  
  42.     kraj:
  43.         movl 8(%esp), %edx
  44.         movl $0, (%edx)
  45.         movw %ax, (%edx)
  46.  
  47.  
  48.     movl %ebp, %esp
  49.     popl %ebp
  50.     ret
  51.    
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. ########################### njegov C kod ############################
  59. #include <stdio.h>
  60.  
  61. void SetParity(unsigned short int* v);
  62.  
  63. void printbin16(unsigned short int x) {
  64.     unsigned short int m=0x8000, s=0;
  65.     while(m) {
  66.         printf("%s%s",m&x ? "1" : "0",++s%8 ? "" : " ");
  67.         m >>= 1;
  68.     }
  69.     printf(" (%d)",x);
  70. }
  71.  
  72. int main() {
  73.     unsigned short int v = 41226;
  74.     printf("\nVrednost pre  : ");
  75.     printbin16(v);
  76.     SetParity(&v);
  77.     printf("\nVrednost posle: ");
  78.     printbin16(v);
  79.     printf("\n");
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement