Arithmetic: Z80 Assembly Language for the ZX Spectrum Tutorial, Episode 5

  Рет қаралды 5,369

The Retro Desk

The Retro Desk

Күн бұрын

Пікірлер: 24
@doctorsimon210
@doctorsimon210 3 ай бұрын
Massive respect for the detail in these tutorials. I am commencing my journey in ZX Spectrum Z80 Assembly and your videos are amazing. Your voice is easy to listen to too. Thank you 🙂
@TheBeeshSpweesh
@TheBeeshSpweesh 3 жыл бұрын
25:58 - 16-bit ADC still sets S, Z, and P/V, like 16-bit SBC does. These flags can be set for a normal 16-bit addition to HL by using a "clear carry" opcode followed by the ADC.
@slithymatt
@slithymatt 3 жыл бұрын
That's not what I've seen in emulation.
@ped7g
@ped7g 3 жыл бұрын
@@slithymatt 16 bit adc does set also ZF/SF/OV "as defined". If you don't see it in your emulator, you have probably inaccurate emulator. But in video I see fuse.. that should definitely emulate it correctly.
@slithymatt
@slithymatt 3 жыл бұрын
@@ped7g I'll have to try it again. Pretty sure I tested ADC with 16bit.
@slithymatt
@slithymatt 3 жыл бұрын
@StinkerB06 - I tried it again in Fuse, and I'll be damned, I could get those bits with 16-bit ADC. I could have sworn I tested that before. I'm going to fix the slides in the repo and put a card in the video
@ZxSpectrumplus
@ZxSpectrumplus 6 ай бұрын
Hi, i don't understand how do you get 104 (signed A) on the line add a,b. -24+-128=-132. Where does the +ve 104 comes from? Thanks.
@slithymatt
@slithymatt 6 ай бұрын
Because -132 is outside the bounds of signed 8-bit integers: -128 to 127. You get an overflow adding xE8 and x80, which gets you x68 (decimal 104) with a carried bit, so effectively x168 if you take the result as a 9-bit signed integer, which could then be interpreted as -132.
@2kBofFun
@2kBofFun Жыл бұрын
Nice tutorials. I want to make a (dis)assembler for the P2000T, also using a Z80. Do you know which instructions the average game for the ZX use? Or do you need every instruction to be present.
@slithymatt
@slithymatt Жыл бұрын
You really need to have them all.
@tijno75
@tijno75 2 жыл бұрын
Hi Matt, why was the Overflow flag set when adding 232(-24) with 128(-128) and not set when adding 226(-30) with 220(-36)? Both additions of two negative numbers produce a positive number result.
@slithymatt
@slithymatt 2 жыл бұрын
The second addition does have a negative result: (-30) + (-36) = -66. This is why 226 + 220 = 190 with just a carry and no overflow.
@johncochran8497
@johncochran8497 3 жыл бұрын
On ADD HL,ss The H bit is not undefined. It indicates a carry out of bit 11. But I will agree that it's pretty useless since the purpose of the H and N bits is to allow the DAA instruction to properly adjust the value in the A register for BCD arithmetic and the required information to adjust bits 4-7 and 8-11 are lost. Basically, if you want to do BCD math, you gotta stick with 8 bit addition and subtraction. The issue with ADC HL,rr has already been addressed in another comment. The code at 25:27 takes 5 bytes, not 4. I was surprised at you using CP A to clear the C flag. It seems to be more common to use a logic operation such as OR A, but both work and take the same space and time. You can still obtain the Z80 user manual from zilog, which documents all of the Z80 opcodes. But the undocumented ones are not specified (those using IXL,IXH,IYL,IYH and the like).
@slithymatt
@slithymatt 3 жыл бұрын
I used CP A because I've already covered the effects of CP in the previous video, but I haven't gone over OR yet, properly. It was also a nice conversation to tie back how the CP effects happen after seeing how SUB and SBC work. Good catch on the byte count of that SBC opcode. I've fixed the slides in the repo. All told, the number of mistakes I made in this video are refreshingly few considering how dense this one turned out. I'll definitely get into a lot more of this in the advanced math episode coming later in the series, when I'll be doing BCD along with multiplication and division. The "Advanced Math" episode of my X16 tutorial series is going to be the template for that.
@TheBeeshSpweesh
@TheBeeshSpweesh 3 жыл бұрын
@@slithymatt Are you double- or triple-checking your slides and script before they go out the door onto KZbin?
@slithymatt
@slithymatt 3 жыл бұрын
@@TheBeeshSpweesh at least double checking. I need a fact-checking department to take care of this for me, but my revenue is just a TAD below what it needs to be for that. It took 3 weeks to compile all of this information that is not put in one coherent place, and the hundreds of data points that generates is a bit overwhelming. Missing a handful out of that could be a lot worse. I'll take that record over that of most news outlets.
@d2factotum
@d2factotum 3 жыл бұрын
In your routine to print the contents of the flag register, would it not have been easier to get the contents of that register into one of the ones you could actually work with by using push af followed immediately by pop bc?
@slithymatt
@slithymatt 3 жыл бұрын
Not really, because I would have had to push it back on the stack.
@d2factotum
@d2factotum 3 жыл бұрын
@@slithymatt I meant in addition to the push af you already had--I'm pretty sure a push and a pop together would take less space and possibly less cycles than all that messing about with scratch memory.
@slithymatt
@slithymatt 3 жыл бұрын
@@d2factotum looking at the cycles, it would take a lot less to do it your way (24 vs. 47 T-states), but then you lose all the fun of stack introspection. ;)
@DAVIDGREGORYKERR
@DAVIDGREGORYKERR 3 жыл бұрын
These routines would implement floating point, double and long double math should it not, if you are interested what about getting the MEMOTECH MTX512 Program Book which has a MTX BASIC + ASSEMBLER program called Sound To Light.
@slithymatt
@slithymatt 3 жыл бұрын
Going into floating point is a bit beyond where I plan on going in this series, but I will be getting into how to do integer and fixed-point multiplication and division in the upcoming "Advanced Math" episode
@DAVIDGREGORYKERR
@DAVIDGREGORYKERR 3 жыл бұрын
@@slithymatt it is but floating point on the Spectrum boils down to 5 bytes four which are the Mantissa and one which is the exponent and 1 bit of the exponent will be the sign flag.
The Stack: Z80 Assembly Language for the ZX Spectrum Tutorial, Episode 6
17:21
HELP!!!
00:46
Natan por Aí
Рет қаралды 17 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 210 МЛН
MAGIC TIME ​⁠@Whoispelagheya
00:28
MasomkaMagic
Рет қаралды 22 МЛН
I found the greatest ZX Spectrum BASIC programmer of all time
9:51
hotdog soup 🌭🥣
Рет қаралды 16 М.
Understanding the Z80 Memory Map
14:12
Kenneth Finnegan
Рет қаралды 31 М.
4. Assembly Language & Computer Architecture
1:17:35
MIT OpenCourseWare
Рет қаралды 721 М.
Just enough assembly to blow your mind
29:31
Kay Lack
Рет қаралды 117 М.
Interrupts: Z80 Assembly Language for the ZX Spectrum, Episode 12
27:52
Something Strange Happens When You Take This To Its Logical Conclusion
32:44