Article View: pl.comp.lang.asm
Article #1089GCC inline asm
From: Damian 'legion' Szuberski
Date: Tue, 01 May 2007 15:13
Date: Tue, 01 May 2007 15:13
45 lines
1630 bytes
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
Technical Details
Message-ID:
<f17lek$lk4$1@news.onet.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail From: Damian 'legion' Szuberski <legion@wmid.amu.edu.cutthisjunk.pl> Newsgroups: pl.comp.lang.asm Subject: GCC inline asm Date: Tue, 1 May 2007 15:13:24 +0000 (UTC) Organization: Onet.pl Lines: 45 Message-ID: <f17lek$lk4$1@news.onet.pl> NNTP-Posting-Host: bastion.campus.luth.se Mime-Version: 1.0 X-Trace: news.onet.pl 1178032404 22148 130.240.201.225 (1 May 2007 15:13:24 GMT) X-Complaints-To: usenet@news.onet.pl NNTP-Posting-Date: Tue, 1 May 2007 15:13:24 +0000 (UTC) X-Sender: r9wfgjZVbN1wMLpeEh7o81UXY43M1DYm User-Agent: slrn/0.9.8.1 (Linux) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit