I need to add two numbers of more than 255 bits in assembler


I know it's a very basic question, but I'm eating my head trying to figure out how it's done.

I am using a Motorola 6800 with this emulator.

I have two numbers, and their sum gives more than 255, I know I have to use ADC but I do not know how to save the result.

ldaa #255 ; Cargar primer numero(255) en el acumulador A
staa $00f0 ; Guardar A en la memoria $00f0
ldaa #30 ; Cargar segundo numero(30) en el acumulador A
adca $00f0 ; Añadir ambos numeros con carry

Here I am with the carry flag in 1, and the number 29 in the accumulator A (which as far as I know, means that the result is 255 + accA + 1).

How do I save the result?

asked by Mati Wainsten 25.02.2018 в 00:55

2 answers


Numbers greater than accumulators can be defined in memory, with   adc you can add numbers of more than 8 bits. In this code I do not use adc , because they are only eight bits. I'm not sure if those are the instructions are precise, but I detail the principle in the comments.

ldaa #255  ; Cargar sumando 255 en [00f0]
staa $00f0
clr  #00f1 ; Vaciar [00f1] para guardar ahí el resultado sin acarreo
clr  #00f2 ; Vaciar [00f2] para guardar el acarreo
ldaa #30   ; Cargar sumador 30 en A
adda $00f0 ; Sumar A + [00f0] y guardarlo en A y carry queda en 1
staa $00f1 ; guardar la suma en [00f1]
bcc        ; branch si no hay nada en el carry
inc  $00f2 ; si hubo algo en el carry, colocar en 1 [00f2]

... and the memory is already saving the result in memory.

answered by 25.02.2018 в 02:22

The assembly language that I know is ARM.

But basic knowledge of Assembler and even high level: The result is saved in 8 bits, therefore you can not easily save it.

What you can do is try to use registers or variables with more bit lengths to avoid losing that precision. As far as I know, you can not keep the Carry, because it's a temporary Flag. What you may be able to do is be careful not to crush the Carry and read it to finish writing the subsequent conditions or later values you need.

answered by 25.02.2018 в 01:07