atarionline.pl asm question - Forum Atarum

    Jeśli chcesz wziąć udział w dyskusjach na forum - zaloguj się. Jeżeli nie masz loginu - poproś o członkostwo.

    • :
    • :

    Vanilla 1.1.4 jest produktem Lussumo. Więcej informacji: Dokumentacja, Forum.

      • 1: CommentAuthorw1k
      • CommentTime14 Apr 2010 19:04 zmieniony
       
      how can i do in asm this?
      for i=1 to 10:?i:next i

      how i count from 1 to 10?

      i have this example:
      run $2000
      org $2000

      ldx #0
      loop inx
      stx $bc40
      jmp loop


      then o mod it:
      clc
      lda #0
      loop adc #1
      cmp #10
      sta $bc40
      bne loop
      end


      not work..
      • 2: CommentAuthormono
      • CommentTime14 Apr 2010 20:04 zmieniony
       
      scrad equ $58 ;.w
      adr equ $80 ;.w

      ldx scrad
      ldy scrad+1
      stx adr
      sty adr+1
      ldx #0
      ldy #0
      loop:
      iny
      tya
      ora #$10
      sta (adr,x)
      lda #40
      adc adr
      sta adr
      bcc *+4
      inc adr+1
      cpy #10+1
      bcc loop
      rts


      Edit: Sorry - this code print ':' as 10 :( Look forward for better routine.
      • 3:
         
        CommentAuthorPecus
      • CommentTime14 Apr 2010 20:04
       
      w1k: swap STA and CMP.
      • 4: CommentAuthorw1k
      • CommentTime14 Apr 2010 20:04
       
      jesus..
      it's to hard to understand..:(
      why $80? (128?)
      can you comment that code please? thank you
      • 5: CommentAuthormono
      • CommentTime14 Apr 2010 20:04 zmieniony
       
      @Pecus: sta don't touch flags - it's no problem.

      @w1k: $80..$ff is the user space area on zero page. You can free use these registers.

      But If you want to count and print 2-digit numbers then you need following code:
      scrad equ $58 ;.w - begin of screen
      adr equ $80 ;.w - my work register with address of screen row
      dec equ $82 ;.b - counter in bcd

      ldx scrad ;move first screen row address
      ldy scrad+1 ;to work row address
      stx adr
      sty adr+1
      ldx #1 ;for i=1
      @loop:
      txa ;convert binary number to bcd
      jsr bin2dec

      pha
      lsr @
      lsr @
      lsr @
      lsr @
      ora #$10 ;'0' internal code
      ldy #0 ;column #0
      sta (adr),y ;print dec

      pla
      and #$f
      ora #$10 ;'0' internal code
      iny ;column #1
      sta (adr),y ;print units

      clc ;calculate next screen row address
      lda #40 ;screen width
      adc adr
      sta adr
      bcc @pass
      inc adr+1
      @pass:
      inx ;next i
      cpx #10+1 ;...to 10
      bcc @loop
      rts

      ;bin to bcd conversion
      bin2dec:
      ldy #0 ;clear work register
      sty dec
      ldy #8 ;count of bits in byte
      sed ;bcd mode on
      @loop:
      asl @ ;bit shift work only as binary operator (multiplies by 2 in binary)
      lda dec ;multiplies by 2 in bcd mode
      adc dec ;and shift in C from binary number
      sta dec
      dey
      bne @loop
      cld ;bcd mode off
      lda dec ;dec has bcd value of A on input
      rts
      • 6: CommentAuthortebe
      • CommentTime14 Apr 2010 20:04
       
      org $2000

      .var .byte i = 1

      #while .byte i<=#10

      ldx i

      lda #$ff
      sta $bc40,x

      inc i
      #end
      rts
      • 7: CommentAuthorw1k
      • CommentTime14 Apr 2010 20:04
       
      hmm..
      if i'm a totally novice with asm, with which should i start?
      • 8: CommentAuthormono
      • CommentTime14 Apr 2010 21:04
       
      I know only publications in Polish. IMHO best one is "Assembler 6502" by Jan Ruszczyc ->link<- . Memory map is described in "Mapping of the Atari", but system is detailed in books of Wojciech Zientara ->link<- . Unfortunatelly all (but "Mapping of the Atari") in Polish.
      • 9: CommentAuthorw1k
      • CommentTime14 Apr 2010 21:04
       
      i understand polish.. tommorow i starting learn
      (czech/slovak books is it too poor for informations)
      • 10: CommentAuthor0xF
      • CommentTime15 Apr 2010 09:04
       

      w1k:

      then o mod it:
      clc
      lda #0
      loop adc #1
      cmp #10
      sta $bc40
      bne loop
      end



      Actually it works, but the whole program completes in a 1/15000 of a second. That's why you see just the final result, which is one character of ANTIC code 10.

      If you're switching from BASIC, keep in mind that asm is thousands times faster.

      The book by Ruszczyc is the best for beginners.
      • 11:
         
        CommentAuthorjhusak
      • CommentTime15 Apr 2010 09:04
       
      @w1k - twój przykład:
      run $2000
      org $2000

      ldx #0
      loop inx
      stx $bc40
      jmp loop

      nie działa, bo jest nieskończona pętla.

      Twój drugi przykład działa natomiast dobrze, chociaż warto zawsze rozkazy zmieniające flagi (zero flag w tym przypadku Cię interesuje z powodu BNE) ustawiać bezpośrednio PRZED instrukcjami je sprawdzającymi (BNE w tym przypadku).
      • 12: CommentAuthorxxl
      • CommentTime15 Apr 2010 10:04
       
      org $bc40
      dta $11
      org $bc40
      dta $12
      org $bc40
      dta $13
      org $bc40
      dta $14

      itd.
      • 13: CommentAuthorilr
      • CommentTime15 Apr 2010 13:04