cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/24/12:18:16

From: GAMMELJL AT SLU DOT EDU
Date: Wed, 24 Dec 1997 11:15:21 -0600 (CST)
Subject: By George, I think I've got it
To: djgpp AT delorie DOT com
Message-id: <01IRJTE96R2ABL423S@SLU.EDU>
Organization: SAINT LOUIS UNIVERSITY St. Louis, MO
MIME-version: 1.0

//This is an example of looping and addressing arrays inside a loop
//in GCC assembly assembly language.
//The program sets a vector of unsigned integers x[i]=i, i=1 to 10.
//There are no input or output lines (they are blank).  The array is
//addressed in in the movl statement below L1 (i is ecx).  The _ before x,
//the ( and , after x (rather than [ as one might guess for C/C++), and
//the ,4 (4 is length of an unsigned integer) are all just part of the
//syntax.

#include <iostream.h>

#define mode3()                                                     \
__asm__ (                                                           \
   "movl $0x0, %%ecx;"                                              \
   "L1: addl $0x1, %%ecx;"                                          \
   "movl %%ecx,_x(,%%ecx,4);"                                       \
   "cmp $0xA, %%ecx;"                                               \
   "jne L1"                                                         \
   :                                                                \
   :                                                                \
   : "ecx");

unsigned int x[15];

int main()                                                         {
  int i;
  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