W
W
watmag2017-06-13 23:29:19
Iron
watmag, 2017-06-13 23:29:19

Why do other memory models not work in this code (only the flat memory model works)?

Hello
I am writing a program on tasm

.model flat, C; 1 segm
; сегмент данных

.data
  count DW 2, 0
  

; сегмент кода
.code

laba proc C, source:qword, result:qword

  mov ecx, dword ptr [result]
  

  
              ;загружаем адрес переменной result
  FLD qword PTR [ecx]		;загружаем значение переменной result, используя ее адрес
              ;загружаем адрес переменной source
  FLD source	;загружаем значение переменной source, используя ее адрес
  FLD1		; загружет  1 в ст0 	
  
  FADD ST[0],ST[1]; 1+a
    FSQRT
    FSTP ST[2]; rezultat v st2
    FLD1; 
    FSUB ST[0],ST[1]
    FSQRT
    FST ST[1]
    FLD ST[2]
  FPATAN;вычисляет арктангенс,  принимает 2 переменнве ст 0 и ст1 
  FIMUL count
              
  FSTP qword PTR [ecx];		;заносим результат (ST[0]) в переменную result и выталкиваем значение из регистра ST[0]
  RET						;выходим из подпрограммы
  laba endp
end

This function must be called through C code.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

extern "C"
{
  void laba(double a, double &b);
}

void main()
{
  double a = 0;
  double b = 0;
  scanf("%lf", &a);
  laba(a, b);
  printf("%.10lf\n", b);
}

the program works only with the flat memory model. Any other type does not work. Please tell me how to choose the right memory model for the program and why other types do not work and how to make other types work?
Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2017-06-13
@watmag

So you have a 32-bit code. All these "memory models" and the differences between them are all from the 16-bit world. In a 32-bit world, the model defines the OS, the application program can't do anything about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question