I'm trying to write a program to get a sum of 3 values and getting the mean. So far, I was able to get the sum "correctly" by subtracting a certain value from the sum to get the leading digit of the sum. Subtracting 27h/29 from the sum may not be the most effective method. I know that this may not be the optimal solution, but using division gives me some errors and displays some random symbols as seen on the block I turned into comments.
TITLE Add (sum.asm)
; This program adds 8-bit values
.model small
.stack 100h
.data
ThreeBytes db 10h, 20h, 30h ;expected sum is 60h or 96d
message db 0ah, 0dh,"Sum = "
TheSum db ?, 0ah, 0dh, "$"
.code
main PROC
mov ax, @data
mov ds, ax
mov al, ThreeBytes
add al, ThreeBytes + 1
add al, ThreeBytes + 2
;sub al, 40
; mov ch, 0
; mov ch, al
; mov bl, 10
; div bl
sub al, 27h ;or 39d to get 9
mov TheSum, al ;output is ' (apostrophe) = 60h or 96d
mov dx, offset message
mov ah, 9
int 21h
mov ax, 4C00h
int 21h
main endp
end main
Here is the output that I'm getting from DOSBox:
I am a complete beginner with little to no knowledge of assembly language, so I'm hoping for a simple solution/explanation. The code above is a combination of different programs I found, and it does kinda work.