delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/23/22:07:51

From: GAMMELJL AT SLU DOT EDU
Date: Tue, 23 Dec 1997 21:05:19 -0600 (CST)
Subject: Looping in assembly language
To: djgpp AT delorie DOT com
Message-id: <01IRIZPEXM9EBL3O7M@SLU.EDU>
Organization: SAINT LOUIS UNIVERSITY St. Louis, MO
MIME-version: 1.0

//In the gnu C/C++ interface of assembly and C/C++ how do I store
//x[ecx] in the loop running from L1 to jne L1?
//I would not need the input ("g" (i)) or the output ("=m" (x[i])
//and the line "for (i=1;i<11;i++) mode3();" could be just "mode3();".
//Of course, the assembly line "cmp %1, %%ecx;" would become
//"cmp $0x10, %%ecx;"--there is no problem with that.

#include <iostream.h>

#define mode3()                                                     \
__asm__ (                                                           \
   "movl $0x0, %%ecx;"                                              \
   "L1: addl $0x1, %%ecx;"                                          \
   "movl %%ecx,%0;"                                                 \
   "cmp %1, %%ecx;"                                                  \
   "jne L1"                                                         \
   : "=m" (x[i])                                                   \
   : "g" (i)                                                      \
   : "ecx");

unsigned int x[20];
int i;

int main()                               {
for (i=1;i<11;i++) mode3();      //should be able to replace with mode3
for (i=0;i<11;i++) cout<<x[i]<<'\n';    //and let assembly do the looping
return 0;                                }   //as in Watcom example below
                                             //but I don't see exactly how
//he Watcom code is:
//#include <iostream.h>

//int i;
//unsigned int x[20];

//void mode3();
//#pragma aux mode3 = \
//   "mov ecx, 0",                                              \
//   "L1: add ecx, 4",                                          \
//   "mov x[ecx], ecx",                                         \
//   "cmp ecx, 40",                                             \
//   "jne L1"                                                   \
//   modify [ EAX ECX EDX ];

//int main()                                                         {
//  mode3();
//  for (i=0;i<11;i++) cout<<x[i]<<'\n';
//  return 0;                                                        }


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019