Machine code question

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Machine code question

Post by Crayon21 »

So. i'm slowly but surely starting Machine code programming and I wanted to know if this program is accurate
It gives a 0 which I assume means an overflow:


NEW ROM ONLY
210100 LD HL,1
01FFFF LD BC,65535
09 ADD HL,BC
44 LD B,H
4D LD C,L
C9 RET

I ran it using HexLD and wanted to be sure i wasn't mistaken.

Is it a mistake or does 0 mean overflow? :?:
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Machine code question

Post by mrtinb »

You’ve just added $0001 to $FFFF, and that gives $0000, so your program works fine.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Re: Machine code question

Post by Crayon21 »

much obliged :D
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Machine code question

Post by dr beep »

Crayon21 wrote: Mon Nov 08, 2021 5:38 am So. i'm slowly but surely starting Machine code programming and I wanted to know if this program is accurate
It gives a 0 which I assume means an overflow:


NEW ROM ONLY
210100 LD HL,1
01FFFF LD BC,65535
09 ADD HL,BC
44 LD B,H
4D LD C,L
C9 RET

I ran it using HexLD and wanted to be sure i wasn't mistaken.

Is it a mistake or does 0 mean overflow? :?:
0 is the result of the sum of both registers, but it is does not mean overflow, the overflow is in the Carry-flag.
If the registers would be units only then 6+4 would also give 0, but the carryflag would indicate the 10-position.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Machine code question

Post by XavSnap »

Hi,

There is a possible confusion with this 'C' register and the 'C' carry-flag from the AF register.

"C" is the lower part of the BC register. (LD A,C ; SUB C ...)
and "C" is the carry-flag condition from several intenal Z80 functions. (RET C ; JR C,* ; JP C,*)

They should rename this stat AF flag differently ...
:mrgreen:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Machine code question

Post by 1024MAK »

Well, one is an 8 bit register called C. Which can be combined with the B register to be treated as a 16 bit register (BC).

The carry flag (C) is one of six flag bits in the flag register (F). The flag register is actually 8 bits wide, but two bits are treated as unused. Although it is a real register, you can’t use it like a normal register.

A simple guide on the most used flags is here. More details on the flags / flag register are here. You will find similar information in the various books on the Z80 as well.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply