🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.asm
1 messages
1 total messages Started by Damian 'legion' Szuberski Tue, 01 May 2007 15:13
GCC inline asm
#1089
Author: Damian 'legion' Szuberski
Date: Tue, 01 May 2007 15:13
45 lines
1630 bytes
Mam do zaimplementowania funkcję strlen w GCC inline asm. Niestety mój
kod produkuje bzdury a ja pomimo usilnych poszukiwań nie mogę znaleźć
błedu:

#v+

#include <stdio.h>
#include <string.h>

long unsigned int mystrlen(char *s);

int main(int argc,char *argv[]) {
	printf("%lu - %lu\n",strlen(argv[1]),mystrlen(argv[1]));
	return 0;
}

long unsigned int mystrlen(char *s) {
        long unsigned int len;
        asm volatile("xor %0, %0\t\n"
		     "strlen_loop:\t\n"
		     "cmp $0, (%1)\t\n"
		     "je end_of_strlen\t\n"
		     "inc %0\t\n"
		     "inc %1\t\n"
		     "jmp strlen_loop\t\n"
		     "end_of_strlen:\t\n"
		     : "=a"(len),"=b"(s)
		     : "a"(len),"b"(s)
	     );
	return len;
}

#v-

Po kompilacji i próbie uruchomienia otrzymuję:

#v+
$ ./prog ala
3 - 4021
#v-

Co robię źle? Z góry serdecznie dziękuję za pomoc.

-- 
Damian Szuberski
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads