flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > MCS-80/85

Author
Thread Post new topic Reply to topic
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2015, 07:03
Here is the new support for i8080/85 CPUs

I decided to put it separately from the old thread as it uses now fasmg not fasm and much more convenient in use. Bug reports welcome Wink


Description:
Filesize: 13.69 KB
Viewed: 21852 Time(s)

8080-demo-2016.png


Description: Some examples for real Soviet i8080 home made computers
Download
Filename: 8085STUFF.zip
Filesize: 21.91 KB
Downloaded: 1526 Time(s)

Description: Minimal application to place to fasmg examples folder
Download
Filename: 8085.zip
Filesize: 2.26 KB
Downloaded: 1489 Time(s)


_________________
UNICODE forever!


Last edited by shoorick on 10 Nov 2016, 22:07; edited 5 times in total
Post 18 Aug 2015, 07:03
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 03 Feb 2016, 12:53
New version uploaded.
[-] "$" issue fixed
[-] conditional return bug fixed
[+] old demo with library converted
(you may use Emu or Emu80 to run it, do not forget to press "G<Enter>" to start)

_________________
UNICODE forever!
Post 03 Feb 2016, 12:53
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 04 Aug 2016, 15:25
an integer square root of dword for i8080:
Code:
;=======================================================================
;   BC = SQRT(DEHL)
;-----------------------------------------------------------------------
sqrt32:
;-----------------------------------------------------------------------
    mvi  a,30 + 2
    push psw  ; s+2
    lxi  b, 0 ; y
    push d    ; xh
    push h    ; xl
;-----------------------------------------------------------------------
.loop:
    pop  h
    pop  d
    pop  psw
    sui  2  ; a=s
    rm
;-----------------------------------------------------------------------
    push psw
    push d
    push h
    mov  l,c
    mov  h,b
    dad  h
    mov  c,l
    mov  b,h ; BC=y=2*y
;-----------------------------------------------------------------------
    lxi  d,0
    dad  h
    inx  h   ; DEHL=b=2*y+1
;-----------------------------------------------------------------------
    inr  a
.shift:
    dcr  a
    jz   .skip
    xchg
    dad  h
    jc   .loop
    xchg
    dad  h
    jnc  .shift
    inx  d
    jmp  .shift    
.skip:        ; DEHL << A=s
;-----------------------------------------------------------------------
    push d
    push h
    lxi  h,4
    dad  sp
    xchg    ; DE --> X
    lxi  h,0
    dad  sp ; HL --> B
;-----------------------------------------------------------------------
    ldax d
    sub  m
    mov  m,a
    inx  h
    inx  d
    ldax d
    sbb  m
    mov  m,a
    inx  h
    inx  d
    ldax d
    sbb  m
    mov  m,a
    inx  h
    inx  d
    ldax d
    sbb  m
    mov  m,a
;-----------------------------------------------------------------------
    pop  h
    pop  d
    jc   .loop
;-----------------------------------------------------------------------
    xthl
    pop  h
    xchg
    xthl
    push d
    inx  b
    jmp  .loop    
;=======================================================================    

_________________
UNICODE forever!
Post 04 Aug 2016, 15:25
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 23 Aug 2016, 07:32
a realisation of dividing to 10 via shifting.

the basic implementation was taken there:
Code:
unsigned divu10(unsigned n) {
   unsigned q, r;
   q = (n >> 1) + (n >> 2);
   q = q + (q >> 4);
   q = q + (q >> 8);
   q = q + (q >> 16);
   q = q >> 3;
   r = n - q*10;
   return q + ((r + 6) >> 4);
// return q + (r > 9);
}    


ported to:

Code:
;=======================================================================
;   HL [DE] = HL/10  
;-----------------------------------------------------------------------
proc udiv10
;-----------------------------------------------------------------------
    ora  a
    mov  a,h
    rar   
    mov  b,a
    mov  a,l
    rar
    mov  c,a ; bc = n >> 1
    ora  a
    mov  a,b
    rar
    mov  d,a
    mov  a,c
    rar
    add  c
    mov  e,a
    mov  c,a
    mov  a,d
    adc  b
    mov  b,a
    mov  d,a       ; bc = de = (hl>>1)+(hl>>2) = q
    xchg           ; de = n
    xra  a
    call shr_hl.s4 ; hl = q >> 4 
    dad  b         ; hl = q = q + (q>>4)
    mov  c,h
    mvi  b,0
    dad  b         ; hl = q = q + (q>>8)
    xra  a
    call shr_hl.s3 ; hl = q = q >> 3
    mov  b,h
    mov  c,l       ; bc = q
    dad  h
    dad  h
    dad  b
    dad  h         ; hl = q*10
    mov  a,e
    sub  l
    mov  e,a       ; e = r
    mvi  d,0
    adi  6
    rar
    rar
    rar
    rar
    ani  15        ; a = (r+6)>>4
    add  c
    mov  l,a
    mov  h,b
    rnc
    inr  h
        ret
;-----------------------------------------------------------------------
.dummy = shr_hl 
;-----------------------------------------------------------------------
endp    
;=======================================================================
;
;=======================================================================
;   A MUST BE 0 !
;-----------------------------------------------------------------------
proc shr_hl
;-----------------------------------------------------------------------
.s1:dad  h
    ral
.s2:dad  h
    ral
.s3:dad  h
    ral
.s4:dad  h
    ral
.s5:dad  h
    ral
.s6:dad  h
    ral
.s7:dad  h
    ral
    mov  l,h
    mov  h,a
        ret
;-----------------------------------------------------------------------
endp
;=======================================================================    
Post 23 Aug 2016, 07:32
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 09 Sep 2016, 12:52
a multibyte mathematic is tested - you may check it with attached project. new library and latest fasmg required to compile!


Description:
Filesize: 22.78 KB
Viewed: 20979 Time(s)

mbyte.png


Description:
Download
Filename: MBYTE.0.0.2.1.zip
Filesize: 3.83 KB
Downloaded: 1247 Time(s)

Description:
Download
Filename: lib85.0.6.0.1.zip
Filesize: 18.78 KB
Downloaded: 1286 Time(s)


_________________
UNICODE forever!
Post 09 Sep 2016, 12:52
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
jmg 20 Sep 2016, 21:33
shoorick wrote:
Here is the new support for i8080/85 CPUs



This is cool.

I'm curious about one macro detail you used.
I see irp used
Code:
irp <mnem,opcode>,XCHG?,0EBh,PCHL?,0E9h,XTHL?,0E3h,SPHL?,0F9h,\
                  RLC?, 007h,RRC?, 00Fh,RAL?, 017h,RAR?, 01Fh,\
                  DAA?, 027h,CMA?, 02Fh,STC?, 037h,CMC?, 03Fh,\
                  NOP?, 000h,RET?, 0C9h,RIM?, 020h,SIM?, 030h,\
                  HLT?, 076h,EI?,  0FBh,DI?,  0F3h
    macro mnem 
        db opcode
    end macro
end irp    


That gives quite compact macros, but is it slower/==/faster? than creating a macro-per-opcode ?

Seems the irp has to loop to build the macros, but it does save file-lines-read, and this does run once, compared to many more opcodes in user source files.
Post 20 Sep 2016, 21:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19876
Location: In your JS exploiting you and your system
revolution 21 Sep 2016, 00:06
jmg wrote:
... but is it slower/==/faster? than creating a macro-per-opcode ?
You can test that for yourself with your computer. Let us know the results.
Post 21 Sep 2016, 00:06
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
jmg 21 Sep 2016, 00:42
revolution wrote:
You can test that for yourself with your computer. Let us know the results.


OK, yes that is one 'answer'....
Perhaps a better answer, will come from someone who may have done this already, which is what I was asking ?
Post 21 Sep 2016, 00:42
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 21 Sep 2016, 02:25
it is slower, sure, maybe, for few ┬Ás Wink

A while I do not see any delay with assembling. I can not fit a program more than 32kB into the such model of computer, but even if it were some seconds for assembling, it would not be bothering me Wink

Code:
C:\spec\fasmg\fasmg.exe DEMO.asm DEMO.rks

flat assembler g  version 0.97.1471502275
4 passes, 0.3 seconds, 3066 bytes.    
Post 21 Sep 2016, 02:25
View user's profile Send private message Visit poster's website Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 54
al_Fazline 05 Jan 2023, 08:58
Hello. I have tried to execute the example binary in Radio 86rk emulator (emu80v4), and it seems to just freeze in infinite loop, however the instructions seem to assemble correctly (assembly listing matches debug view disassembly).

Maybe it's meant for a different machine, but the file doesn't have any comments telling which machine it's for.
Post 05 Jan 2023, 08:58
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 06 Jan 2023, 20:32
what exactly was the example which you've tried to execute in radio 86rk emulator?
Post 06 Jan 2023, 20:32
View user's profile Send private message Visit poster's website Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 54
al_Fazline 06 Jan 2023, 21:33
shoorik, there is only one in 8085.zip
Post 06 Jan 2023, 21:33
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 07 Jan 2023, 05:10
it is an example to demonstrate pure binary assembling only.
to see anything in radio-86rk emulator you need use calls to rom functions or more complex write characters to the video memory directly.
also, file to use with those 8-bit emulators must have header and tail as at the tape, there are start and end addresses to load body and the checksum.
rks.inc is to build those things (it produces wrong checksum for rk, as it was created for Specialist and not finished, those models have different bytes order for checksum)

try this to see anything in emu80:
Code:
;=======================================================================
include "8085.inc"
include "rks.inc"
;-----------------------------------------------------------------------
rk_start
;-----------------------------------------------------------------------
    lxi h,hello
    call 0F818h ; output string
    call 0F803h ; wait for key pressed
    jmp  0F800h ; warm boot
hello:
    db 10,10,13,"HELLO",0
;-----------------------------------------------------------------------
rk_end
;=======================================================================    

output binary must have .rk extension
in emu80 press I<enter> and select this rk file, it will load it and show checksum error - ignore it
then press G<enter> to see the message, then any key to reboot (it's just an example)


Description:
Filesize: 7.68 KB
Viewed: 3281 Time(s)

emu80-radio86rk.png


Description:
Download
Filename: rks.inc.zip
Filesize: 729 Bytes
Downloaded: 128 Time(s)

Description:
Download
Filename: HELLORK.rk.zip
Filesize: 181 Bytes
Downloaded: 128 Time(s)


_________________
UNICODE forever!
Post 07 Jan 2023, 05:10
View user's profile Send private message Visit poster's website Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 54
al_Fazline 11 Jan 2023, 22:17
Why not to implement correct trailer for RK tape format? You can use bin2tape tool as reference how to do it.

You need to add `00 00 E6 CKHI CKLO` at the end of your file. 00 00 are optional, but I guess it's better to keep them for compatibility. The checksum is written as big-endian 16-bit value.

It is calculated by summing all but last byte times 101, then adding last byte of data only to the low byte of sum without carry to high 8 byte.
Post 11 Jan 2023, 22:17
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.