Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #void SetParity(word *vrijednost);
- .section .text
- .globl SetParity
- SetParity:
- pushl %ebp
- movl %esp, %ebp
- movl 8(%esp), %eax
- movw (%eax), %ax # %ax broj
- movb $0, %dl #paran/neparan
- movw $1, %cx #maska
- movl $0, %esi #brojac
- while:
- cmpl $15, %esi
- je whileKraj
- testw %cx, %ax
- jz whileBrojac
- # %dl ce za parni ce biti 0, za neparni 1
- xorb $1, %dl
- whileBrojac:
- incl %esi
- shlw $1, %cx
- jmp while
- whileKraj:
- cmpb $0, %dl
- je kraj
- #e sad, ako je neparan negiram prvi bit
- movw $1, %cx
- shlw $15, %cx
- xorw %cx, %ax
- kraj:
- movl 8(%esp), %edx
- movl $0, (%edx)
- movw %ax, (%edx)
- movl %ebp, %esp
- popl %ebp
- ret
- ########################### njegov C kod ############################
- #include <stdio.h>
- void SetParity(unsigned short int* v);
- void printbin16(unsigned short int x) {
- unsigned short int m=0x8000, s=0;
- while(m) {
- printf("%s%s",m&x ? "1" : "0",++s%8 ? "" : " ");
- m >>= 1;
- }
- printf(" (%d)",x);
- }
- int main() {
- unsigned short int v = 41226;
- printf("\nVrednost pre : ");
- printbin16(v);
- SetParity(&v);
- printf("\nVrednost posle: ");
- printbin16(v);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement