Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:31:50+00:00 2026-06-16T00:31:50+00:00

tried returning a long int from asm proc through eax, and later tried through

  • 0

tried returning a long int from asm proc through eax, and later tried through dx:ax. both didn’t work for me as the C printf prints a different number than the required 320L.

x.asm:

.model SMALL
.stack 100h
.code
.386
; extern int get_buffered_long(long int **arr, int num_of_elements, int i);
;                                   [BP+4]      [BP+6]              [BP+8]
PUBLIC _get_bufferred_long 
_get_bufferred_long PROC NEAR
        push BP
        mov BP,SP
        push SI
        push DI
        push BX
        call locate_slot            
        ;mov EAX, DWORD PTR [DI]     ;something here doesn't work. the way i return a long int to borland C, or other issue.
        mov ax,[DI]
        mov dx,[DI+2]
        pop BX
        pop DI
        pop SI
        pop BP
        ret
_get_bufferred_long ENDP
; extern void set_bufferred_long(long int *arr[], int buff_size, int i,long int value);
;                                       [BP+4]      [BP+6]      [BP+8]      [BP+10]
PUBLIC _set_bufferred_long
_set_bufferred_long PROC NEAR
    push BP
    mov BP,SP
    pushad
    call locate_slot
    mov EAX,[BP+10]
    mov DWORD PTR [DI],EAX
    popad
    pop BP
    ret
_set_bufferred_long ENDP
; helper function that makes DI point to the slot wanted.
locate_slot PROC NEAR
    calc_slot:
        mov SI,[BP+4]
        mov AX,[BP+8]
        mov BX,[BP+6]
        xor DX,DX
        div BX
    locate_slot_in_array:
        shl AX,1
        add SI,AX
        mov DI,[SI]
        shl DX,2
        add DI,DX
        ret
locate_slot ENDP
end

y.c:

#include "stdio.h"
#include "stdlib.h"

extern int get_bufferred_long(long int**,int,int);
extern void set_bufferred_long(long int**,int,int,long int);

int main(){
    long int **arr;
    int i,j,n,m;
    n = 5;
    m = 4;
    arr=(long int**)malloc(n*sizeof(long int*));
    for(i=0; i < n; i = i + 2) arr[i] = malloc( m*sizeof(long int));
    for(i=1; i < n; i = i + 2) arr[i] = malloc( m*sizeof(long int));
    for(i=0; i < n; i++)
        for(j=0; j < m; j++) 
            set_bufferred_long(arr, m, i*m+j, i*100+j*10);

    printf("get_bufferred_long(arr, %d, %d) = %ld\n", m, 14, get_bufferred_long(arr,m, 14));
    return 0;
}

the set function works (array looks exactly like needed to). the get function works too, it fetches 320L in asm, but when passed to C, something’s wrong.

no compile errors or warnings.
borland c++ 5.02

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:31:51+00:00Added an answer on June 16, 2026 at 12:31 am

    Well, on a 386 bcc does use AX:DX in 16-bit mode; don’t know about 32 bits.

    But look at your code!

        ...
        mov dx,[DI+2]
        mov ax,[DI]
        mov dx,[DI+2]
        pop DX
        ...
    

    You are loading the DX register with the result and then popping the stack into it, blowing away the value it had. DX does not have to be saved by push/pop in a simple procedure (only e.g. in a DOS ISR).

    EDIT

    Okay I see you fixed the problem above in the code. The next problem is likely to be that you’re declaring

    /* After execution, return value is assumed to be in AX. */ 
    extern int get_bufferred_long(long int**,int,int);
    

    and then expecting a 32-bit return value. You mentioned that the printf is pushing the AX register. This implies you’re compiling to 16-bit code. If you want a 32-bit return value in 16-bit code, you must declare the return value long and place it in DX:AX.

    /* After execution, return value is assumed to be in DX:AX reg pair. */
    extern long get_bufferred_long(long int**,int,int);
    

    You can verify the right return convention by compiling a tiny program to assembly with the -S option. Try for example:

    long val(void) { return 0x12345678L; }
    

    Look at the generated assembly to see what the compiler does to return this long value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display an image from a QAbstractTableModel . I tried returning
I tried getting the type of UnityEngine.Vector3 using Type.GetType() but its returning NULL .
I cannot figure out why appendChild is returning undefined. I also tried t.previousSibling.appendChild(document.createElement('span')); which
Why is Foursquare Campaign Timeseries viewingUsers and unlockingUsers always returning 0? Thanks. I tried
tried uncommenting pam_limits.so from the pam.d directory but no luck. Basic PAM seems to
Tried to search for this online and didn't get very far, so I'm asking
Tried a bunch of things but I can't get it to work consistently amid
I think I understand returning records of an anonymous type from But in this
Tried to create a mobile navigation using dataview or outline and the view renders
Tried searching the site, but cannot find an answer to my problem: Lets say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.