; *** mbyte.asm *** ; code to add two 4-byte values and ; store the result. ; set up the program start and the stack, ; as well as the stop bit so stop will work. org $0800 start: lds #$07ff tpa anda #$7f tap ; set X and Y to point to the LSB of ; the two summands. we'll use B as the ; iteration counter. ldx #val1 ; x points to MSB ldy #val2 ldab #3 abx ; MSB = LSB + 3 aby ; do the addition, one byte at a time, using ; the carry. Start by clearing the carry, since ; there's no carry in to the LSB. push the ; results onto the stack as they come clc addit: ldaa 0,x ; A <- M[x] adca 0,y ; A <- A + M[y] psha dex ; move to next bytes dey decb ; decrement our index count bge addit ; keep going if B>=0 ; at this point we've added all bytes, so ; pull the results off the stack and store them ; in M[sum..sum+3] ldx #sum ldab #3 storit: pula staa 0,x inx decb bge storit stop ; that's the end val1: dw $3C52 ; here's some sample data dw $207A val2: dw $19FF dw $0F0F sum: dw $0 ; the sum should be 56512F89 dw $0 reset: org $fffe ; set up the reset vector dw start