cassemblysic

SIC/XE Can I put new value to a value that already has its own value?


Hi I'm taking a system software class on my uni and I'm making an assembly code with SIC. I've already written a code with C. So I'm translating it to SIC and I got a question about variable policy of SIC. Can I reuse population to store the calculated number? just like C variable? I think it's too basic so I couldn't get an answer when I googled it. Thank you!

int main(void) {
  double current_population = 11778;
  int birth = 180;
  int death= 120;
  double immigrant = 53.333;
  /*one day is 24 hours, so it's1440 minute
    the value of birth and death, immigrant are based on a day. 
  */
  for (int i = 0; i < 7; i++) {
    current_population = current_population + birth + immigrant - death;
    printf("%d day의 인구 : %d\n", i + 1,  (int)current_population);
  }
  return 0;
}    

here is unfinished sic code (very rough)

            LDX   ZERO    
            LDA   population
            ADD   birth
            SUB   death
            ADD   immigrant
            STA   population
population  WORD  11778
birth       WORD  180
death       WORD  120
immigrant   WORD  53

Solution

  • In the SIC code, population is not a variable. It is a name associated with an address. The assembly code population WORD 11778 tells the assembler to put the value 11778 in a word at the next location (in sequence as the assembler progresses through the assembly code) and to associate population with that address.

    Then the question is not whether you can assign a new value to population but whether you can store a new value to that location in memory. A brief look into SIC suggests it is a very simple computer model and there is no provision for read-only memory. In that case, yes, you can store a new value to the location of population.

    In typical assemblers used in production, rather than classroom exercises, there are provisions for preparing code and data in multiple sections. There could be one section for instructions, another section for read-only data, another section for modifiable data, and possibly other sections for special purposes. The assembler has directives for specifying which section the following lines are for. In such an assembler, if you defined data along with instructions, it would go into the code section, sometimes also called the text section. When programs are loaded, the code section is usually marked read-only. So data in such a section could not be modified after it is loaded. To have modifiable data, you would have to put it into a different section.

    SIC does not appear to support multiple sections like this. Presumably everything it assembles goes into one modifiable section.