Post Reply 
Confused about variables
02-26-2016, 09:58 PM (This post was last modified: 02-27-2016 10:13 PM by smp.)
Post: #5
RE: Confused about variables
Tim and Cyrille, thank you very much for your advice.

I have started to get some of my arithmetic code to work properly by using the R->B() command and using the #xx:16h notation on numbers when I perform initialization.

Currently, I am using LOCAL variables for my 8080 registers and flags. I am initializing my them like this:
Code:

//
// initialization
//
// initialize 8080 registers & flags
  pc:=#1:17h;     // program counter  // vector M1 starts with location 1, not 0
  sp:=#0:17h;     // stack pointer
  a:=#0:8h;      // accumulator
  b:=#0:8h;      // B register
  c:=#0:8h;      // C register
  d:=#0:8h;      // D register
  ee:=#0:8h;     // E register
  h:=#0:8h;      // H register
  l:=#0:8h;      // L register
  cf:=0;     // carry flag
  z:=0;      // zero flag
  ac:=0;     // auxiliary carry flag
  s:=0;      // sign flag
  p:=0;      // parity flag
// initialize temporary variables
  d1:=#0:8h;     // instruction fetched from RAM
  d2:=#0:8h;     // second byte of a multi-byte instruction
  d3:=#0:8h;     // third byte of a multi-byte instruction
  t1:=#0:17h;    // temp (larger than 16 bits to capture carry)
// initialize run flags
  r1:=1;     // run flag 1
  r2:=1;     // run flag 2
// clear the terminal screen
  PRINT;
//

I am setting up M1 as a one-column array (or vector) for simulating the memory so I can retrieve instructions like this:
Code:

d1:=M1(pc);

I am incrementing the program counter like this:
Code:

    pc:=pc+#1:17h;
    IF pc>#0FFFF:17h THEN
      pc:=#1:17h;  // vector M1 starts with location 1, not 0
    END;

The bit of code that I've been playing with this afternoon is this:
Code:


  IF d1==57 THEN // DAD SP (HL+SP)
    t1:=#0:17h;
    t1:=t1+h;
    t1:=t1*#100:9h+l+sp;
    h:=(t1/#100:9h) AND #FF:8h;
    l:=(t1 AND #FF:8h);
    CARRY16;
  END;

CARRY16()
BEGIN
  cf:=0;
  IF (t1>#0FFFF:17h) THEN
    cf:=1;
  END;
END;

I have my t1 (temporary) register initialized larger than 16 bits so I can capture the carry from 16 bit arithmetic. The combining of the H and L registers into one 16 bit register, the 16 bit addition with the SP register, and the masking of the H and L registers after the addition are all working properly, BUT h and l both become 17 bit variables.

The 16 bit addition with the result going into the 17 bit t1 variable shows a 17 bit result in the case of a carry overflow, so then I can test t1 for being greater than FFFF as you see. This is working as it should.

I'm happy to be making progress, but I am still learning...

Thanks very much for all your attention and assistance.

smp
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Confused about variables - smp - 02-24-2016, 12:31 PM
RE: Confused about variables - Tim Wessman - 02-24-2016, 03:05 PM
RE: Confused about variables - smp - 02-25-2016, 12:55 AM
RE: Confused about variables - smp - 02-26-2016 09:58 PM
RE: Confused about variables - smp - 02-29-2016, 05:25 PM



User(s) browsing this thread: 2 Guest(s)