Using C functions from IA-32 assembly language
Is it possible to use 32-bit assembly language to call C functions in 64-bit linux?
Background: I'm learning 32-bit AT&T syntax Linux assembly language programming. The only reason for 32-bit is that's what's covered in the book I have. Some simple examples assemble, link, and execute in Arch 64 using GNU either gcc or as + ld -- with no changes either to code or command line flags.
The problem: I'm having trouble with C function calls. Even after replacing register names (e.g., edi -> rdi) and mnemonics (e.g., movl -> movq), I find that a program which calls printf and exit never prints anything, and never returns. Hence the question.
I can post code if needed (it's on my other machine), but this is really more of a general question -- is it possible to call C functions in Arch 64 using 32-bit AT&T syntax, and if so, how.
Thanks!
Not even a typo, just confusion. The CPU is an Intel Core 2 Duo -- so it's actually x86-64.
I realize that NASM is not GAS, but checking the NASM manual helped me figure out a few things about calling 64-bit C functions:
http://www.nasm.us/doc/nasmdo11.html
It took a while to figure out how to correctly call printf. The missing clue was here:
http://www.mit.edu/~6.035/handouts-2007 … convention
printf reads the number of variable arguments from %rax. In this example, printf is called with no variable arguments:
# c_functions.s - Calls 64-bit C functions putchar, printf, and exit
.section .data
a:
.byte 'a'
newline:
.byte '\n'
hello:
.asciz "hello, world\n"
.section .text
.globl main
main:
movq a, %rdi # used as argument for putchar
call putchar
movq newline, %rdi # used as argument for putchar
call putchar
movq $hello, %rdi # first argument for printf (i.e., the format string)
movq $0, %rax # number of variable arguments for printf
call printf
movq $0, %rdi
call exit
For simplicity, I compiled and linked with gcc (in other words, I let gcc figure out how to properly call as and ld):
gcc c_functions.s
If I can figure out how to pass variable arguments to printf, I'll post that. Based on the MIT reference linked above, it sounds like those arguments would be passed in SSE registers.
Similar Messages
-
Hi Gurus,
It is impossible to use SAPGETDATA function from an intermediary level
of a hierarchy with a cell reference.
When I open completely a hierarchy node I manage to get the bottom level
using a cell reference.
But I cannot do the same thing from a level above.
I attach screenshots.
Best regards,
Thierry ChiretHello,
I find the soluce :
Regards,
Thierry -
XSLT using Java function from graphical mapping (RFClookup)
Hi,
I was wondering if it is possible to use the standard Java functions of the graphical mapping (RFCLookup, Datetrans, ...) or from my own UDF inside an xslt mapping. Does anyone have every tried this or is an example available ?
Regards BerndHi Bernd,
here you can find an example how to use RFC lookup from an XSLT Mapping:
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14?quicklink=index&overridelayout=true
Is this what you're looking for?
Regards,
Gábor -
Using a function from another file
Dear friends,
I have two different java files in one folder. One is sm.java and the other is AVTransmit2.java. The code below describes the create Transmitter function in the AVTransmit2.java file. Now if i would like to use this function in sm.java, how do i do it ? The create transmitter function is shown below. Thank You, Gan.P
private String createTransmitter() {
// Cheated. Should have checked the type.
PushBufferDataSource pbds = (PushBufferDataSource)dataOutput;
PushBufferStream pbss[] = pbds.getStreams();
rtpMgrs = new RTPManager[pbss.length];
SessionAddress localAddr, destAddr;
InetAddress ipAddr;
SendStream sendStream;
int port;
SourceDescription srcDesList[];
for (int i = 0; i < pbss.length; i++) {
try {
rtpMgrs = RTPManager.newInstance();
// The local session address will be created on the
// same port as the the target port. This is necessary
// if you use AVTransmit2 in conjunction with JMStudio.
// JMStudio assumes - in a unicast session - that the
// transmitter transmits from the same port it is receiving
// on and sends RTCP Receiver Reports back to this port of
// the transmitting host.
port = portBase + 2*i;
ipAddr = InetAddress.getByName(ipAddress);
localAddr = new SessionAddress(InetAddress.getLocalHost(),
port);
destAddr = new SessionAddress(ipAddr, port);
rtpMgrs.initialize(localAddr);
rtpMgrs.addTarget(destAddr);
System.err.println( "Created RTP session: " + ipAddress + " " + port);
sendStream = rtpMgrs.createSendStream(dataOutput, i);
sendStream.start();
} catch (Exception e) {
return e.getMessage();
return null;
}Kalani and Bz,
Thanks for the reply. Now i can call the function ,
but when i write sendStream.start(); it indicates
that, its an error. sendStream.start is in that
function. but i cant call that
Any idea ?
thank you
Gan.PCan you please inform what is the error ? -
Using PostLVUserEvent function from Labview.dll
I am trying to use the PostLVuserEvent function from the labview.dll and corresponding extcode.h file. I have made my own dll using CVI that uses this function. I then use Labview to call my dll. My dll compiles fine. No issues, no errors. LabView can call my dll function containing the PostLVUserEvent function with no errors. However, the event number LabView passes my dll is not the same event number I receive so no LabView event is triggered.
Has anyone had this issue?
We are trying to solve it from the LabView side and the CVI side but cannot seem to get it to work. The examplesI have found here were compiled using C++ and those seem to work. I do not know why when I compile my program in C, it creates the dll but does not work. If I had to guess, i think it's an issue with pointers vs non-pointers. When the LAbview program selects my function from the dll, it shows the argument PostLVUserEvent as a pointer when in my dll, it is not a pointer PostLVUserEvent....
Any ideas?
Thanks in advance.Hello Blue
Take a look to this one, it was created on C, I think the .c and the .h files will give a good idea, how the function should be implemented. It is important when calling the dll on LabVIEW, to use the std calling convention and run it on the UI thread.
Regards
Mart G
Attachments:
LabView EventTest.zip 1041 KB -
New to FIOS TV Multi-room DVR - Should I be able to use DVR functions from the other HD STBs?
We just converted from Directv (three DVRs) to FIOS TV and am hoping I didn't make a huge mistake: The sales agent I spoke to said that the Multi-room DVR (Motorola QIP-7216-1) and non-DVR STB would enable me to get the same features I had with my Directv setup so each user could Stop/Start/Record programming from their own remote. Unless I'm doing something wrong, I can only perform DVR control functions from the real DVR. I can view recorded programming on the non-DVR STBs but pressing record for a live broadcast or trying to select a show to record from the guide doesn't work.
I have the ActiontecGen2 MOCA connected MI424WR router, three HD STBs (Motorola 7000), one standard definition STB and the DVR.Tomd514 wrote:
We just converted from Directv (three DVRs) to FIOS TV and am hoping I didn't make a huge mistake: The sales agent I spoke to said that the Multi-room DVR (Motorola QIP-7216-1) and non-DVR STB would enable me to get the same features I had with my Directv setup so each user could Stop/Start/Record programming from their own remote. Unless I'm doing something wrong, I can only perform DVR control functions from the real DVR. I can view recorded programming on the non-DVR STBs but pressing record for a live broadcast or trying to select a show to record from the guide doesn't work.
I have the ActiontecGen2 MOCA connected MI424WR router, three HD STBs (Motorola 7000), one standard definition STB and the DVR.
As you've found, you can only create recordings from the DVR. If you want each room to have the ability to schedule recordings, then you need a separate DVR in each room.
The FiOS Motorola DVRs cannot access recordings stored on other DVRs.
If you are the original poster (OP) and your issue is solved, please remember to click the "Solution?" button so that others can more easily find it. -
Problem using isChannelSecure() function from SecurityService Interface
Hi everyone
I'll appreciate if anyone could tell me what is exactly the properties arguman in
boolean isChannelSecure(byte properties) function from SecurityService Interface.
Best Regards
ShanarAPI?
-
How to use custom functions from Dlls
I would like to know if there a way to import functions from
a custom DLL?
ThanksHi Wardell,
Did you get any break through on this I was exploring on same.
Egarly awaiting reply....
Regards,
Ankeet Pujara -
Can't use Export Functionality from form?
Hi experts,
I got a problem now, can anyone help me??
This's my system information:
APPLICATION: 11.5.10.2
DATABASE: 9.2.0.6.0
And the problem is:
- Open 1 Form
- File > Export
- The progress bar update to 100%
- The browser is opened
And it suddenly disappear.
I've checked metalink and see this note: 423261.1 How to Troubleshoot Forms Hanging Using Export Functionality
I think it's fail in phase 4:
4) Finally generate the URL, and display the file in the browser window by calling the Forms built-in web.show_document
But i don't know how to solve this problem. Can anyone show me?
Thank you so muchHi everybody,
I solved my problem. In my case, it's because tablespace CTXD was not have enough free extent. You can check this note
Information You Should Upload When Creating an SR for File Export and Attachments Doc ID: Note:427964.1
Hope that helps, -
Authentication failed while using the function from JSP.
I am facing a issue with the mail functionality with JAVA Mailing.The problem is that when I am running the stand alone program it is working fine but when same function is called from a JSP it gives Authentication failed Exception.I am attaching the code with the case.testMail() Is the function called from the JSP.
Please Look in to the issue its urgent.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimePartDataSource;
To use this program, change values for the following three constants,
SMTP_HOST_NAME -- Has your SMTP Host Name
SMTP_AUTH_USER -- Has your SMTP Authentication UserName
SMTP_AUTH_PWD -- Has your SMTP Authentication Password
Next change values for fields
emailMsgTxt -- Message Text for the Email
emailSubjectTxt -- Subject for email
emailFromAddress -- Email Address whose name will appears as "from" address
Next change value for "emailList".
This String array has List of all Email Addresses to Email Email needs to be sent to.
Next to run the program, execute it as follows,
SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
public class SendMailUsingAuthentication
private static final String SMTP_HOST_NAME = "host";
private static final String SMTP_AUTH_USER = "username";
private static final String SMTP_AUTH_PWD = "password";
private static final String emailMsgTxt = "Test Msg";
private static final String emailSubjectTxt = "Notification: New User created";
private static final String emailFromAddress = "[email protected]";
// Add List of Email address to who email needs to be sent to
private static final String[] emailList = {"[email protected]"};
public static void main(String args[]) throws Exception
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
public void testMail(String msgBody,String senderEmail)throws MessagingException
try{
String mailBody = msgBody;
String senderEmailAdd = senderEmail;
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, mailBody , senderEmail);
catch(MessagingException me) {
//System.out.println("Mail not sent");
throw me;
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
try{
boolean debug = false;
//Set the host smtp address
Properties props = System.getProperties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
catch(MessagingException me) {
//System.out.println("Mail not sent");
throw me;
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
public static class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);Your code doesn't work in stand alone program... just little mistake!
Miss port property :
props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable", "true"); // tls for gmail
AddressTo method didn' t compile :
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress((String) recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
And see this post for jsp integration :
http://forum.java.sun.com/thread.jspa?threadID=5184860&tstart=0 -
Using a function from static context..
Well I have a command line app; and it has a public static void main. Now, I made a function that writes to a file, and tried calling it from the main section, and it got mad saying I can't call it from static context. Anyway to allow it to be called from both static and non static contexts?
otherwise create object of the class, from that object you can call a method
-
Using Parent Functions from Child
I have created an application utilizing numerous components.
Each component encompasses it's own functions. This has become an
issue as the application has grown and I need to refresh components
based on the click of a tab navigator.
Being very new to flex 2 I am wondering how I could put all
of the functions now in the components on my main.mxml and call
them from the children (components)? I believe that this would
allow me an easy way to refresh the different components utilizing
a large init() function in main.mxml.
Also, is it possible to call the init() functions of my
components from the main.mxml. This would also allow me to refresh
components. If it's possible I would like to see a simple example
of the process.
Thanks for the help. I appreciate it.
MarkThis code may help:
components/init/InitButton1.mxml---------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Button xmlns:mx="
http://www.adobe.com/2006/mxml"
label="ButtonOne" creationComplete="init()">
<mx:Script>
<![CDATA[
public function init():void {
setStyle("fontWeight", "bold");
setStyle("fontSize", "10");
setStyle("color", "0xFFFFFF");
]]>
</mx:Script>
</mx:Button>
components/init/InitButton2.mxml---------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Button xmlns:mx="
http://www.adobe.com/2006/mxml"
label="ButtonTwo" creationComplete="init()">
<mx:Script>
<![CDATA[
public function init():void {
setStyle("fontWeight", "bold");
setStyle("fontSize", "5");
setStyle("color", "0x000000");
]]>
</mx:Script>
</mx:Button>
----------------------------- Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns:comp="components.init.*"
horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import mx.controls.Button;
public function changeBtn1Styles(event:Event):void {
if(event.target.id != "btn1" && event.target.id !=
"btn2"){
btn1.setStyle("fontWeight", "normal");
btn1.setStyle("fontSize", "30");
public function changeBtn2Styles(event:Event):void {
if(event.target.id != "btn1" && event.target.id !=
"btn2"){
btn2.setStyle("fontWeight", "normal");
btn2.setStyle("fontSize", "40");
public function resetStyles(event:Event):void {
var currBtn:Button = Button(event.currentTarget);
if(currBtn.id == "btn1"){
btn1.init();
if(currBtn.id == "btn2"){
btn2.init();
]]>
</mx:Script>
<mx:TabNavigator>
<mx:VBox label="Button One" width="300" height="150"
backgroundColor="0x0000CC" horizontalAlign="center"
verticalAlign="middle" click="changeBtn1Styles(event)">
<comp:InitButton1 id="btn1"
click="resetStyles(event)"/>
</mx:VBox>
<mx:VBox label="Button Two" width="300" height="150"
backgroundColor="0xCC3333" horizontalAlign="center"
verticalAlign="middle" click="changeBtn2Styles(event)">
<comp:InitButton2 id="btn2"
click="resetStyles(event)"/>
</mx:VBox>
</mx:TabNavigator>
</mx:Application> -
Using function from windows dll in abap program
Hi
How can i use a function from a standard DLL that in c:\winnt\system32.?.
AmiHello ami,
here is the solution to your question - I know, a little bit late, but I hope not to late.
Cheers
Stefan
"-Begin-----------------------------------------------------------------
Report ZLOGON.
"-Variables-----------------------------------------------------------
Data Win32 Type OLE2_OBJECT.
Data Token Type String Value '0000'.
Data hToken Type Integer.
Data phToken Type Integer.
Data ret Type Integer.
"-Main----------------------------------------------------------------
Create Object Win32 'DynamicWrapperX'.
If Win32-Handle > 0.
"-Define external functions---------------------------------------
Call Method Of Win32 'Register' Exporting
#1 = 'advapi32.dll' #2 = 'LogonUserA'
#3 = 'i=sssuup' #4 = 'r=l'.
Call Method Of Win32 'Register' Exporting
#1 = 'kernel32.dll' #2 = 'CloseHandle'
#3 = 'i=h' #4 = 'r=l'.
Call Method Of Win32 'Register' Exporting
#1 = 'kernel32.dll' #2 = 'GetLastError'
#3 = 'r=u'.
Call Method Of Win32 'StrPtr' = phToken Exporting
#1 = Token #2 = 's'.
Call Method Of Win32 'LogonUserA' = ret Exporting
#1 = 'bambi' #2 = '.' #3 = 'hugo' #4 = 2 #5 = 0 #6 = phToken.
If ret <> 0.
"-Logon successful----------------------------------------------
Write: 'Logon as bambi user'.
Call Method Of Win32 'NumGet' = hToken Exporting
#1 = phToken.
Call Method Of Win32 'CloseHandle' = ret Exporting
#1 = hToken.
If ret = 0.
Call Method Of Win32 'GetLastError' = ret.
Write: / ret.
EndIf.
Else.
Call Method Of Win32 'GetLastError' = ret.
Write: / ret.
EndIf.
Free Object Win32.
EndIf.
"-End-------------------------------------------------------------------
Edited by: Stefan Schnell on Sep 6, 2011 7:07 AM -
How can i use function from microsoft DLL in an ABAP program?
Hi
Is there a way to use a function from a standard DLL file in an ABAP progrm ????
The dll is stored in c:\winnt\sttem32.
Do i need to upload the dirver to the ECC server? do i need to put it some Tcode before i use it in my program?
i tried to fined some clear exaple but without any success .
Hope to get some help here ,
thanks ,
E.this is not really possible, a dll cannot be uploaded, eg. sap could run in a non windows-environment so this won't work
Why not? You can query the local operating system for type/version, you can detect the presence of a file if you have the access, and you can run local executables using GUI_EXECUTE. However, if you've got any level of decent security in place, you're not going to be allowed to run a DLL in that location... -
How to add warning message while using 'print' function in Adobe LiveCycle Designer
I am trying to make pdf document for my company which requires adding a warning message while anyone use 'print' function from the page...
Does anyone know how to add warning message on LiveCycle Designer
Also my supervisor mentioned something using 'nag' if that rings any bellNo you shoudl never go into the XML source unless uinstricted to do so.
You can open the script editor (under the window menu). It will appear above the drawing area but below the toolbars. You can resize it if there is not enough room. When you click on an object in the form you can choose an event to script against in the Show dropdown. In your case you will want to choose the prePrint event. A line will show up that indicates the object that is associated with the script as well as the event and other information. Add your script below this line. Once that is done you are finished and your form is ready for testing.
Paul
Maybe you are looking for
-
Speed up BlackBerry Wi-Fi connections a knottyrope tip
These knottyrope tips might help you out. This is not an end all solution but I have come across these issues in the past years. Go slow and document what you do. Worst case is resetting your router to default and starting over. Router running latest
-
SharePoint server 2013 Search Service App on Windows server 2012 R2 not working
Hi all, I installed SharePoint server 2013 on Windows server 2012 R2 using VirtualBox. I created a DC(domain controller) server with a domain set up on one VM and it has SQL server 2012 SP1 installed. Then SharePoint 2013 on another VM was set up t
-
URGENT---EJB 3.0--Toplink essential - loading custom session customizer
Dear all, I am a newbie to EJB as well as JPA...for some reason i need to write a custom session customizer i config the persistence.xml with the following property: <property name = "toplink.session.customizer" value = "customizer.MyCustomizer"/> My
-
How to restore Ipod database without iTunes?
Hi, My iPod mini is visible to any aplication except iTunes. I have tried all it sugested on the manuals to fix it and nothing worked. Others applications like RealPlayer and Anapod can see that the iPod is connect but can´t show its content. RealPla
-
How to move ADF table range navigation towards left?
Hi All, I am using jdev 10.1.3.4. The page I am working is showing a table with many columns. So I need to scroll horizontally to see the table navigation. Is there any way to move the table range navigation to the left so that I dont need to scroll?