Блог пользователя phantom11

Автор phantom11, 13 лет назад, По-английски

I have just started to learn the 8086 assembly language.The task is to print the sum of 2 16 bit numbers.Here's my code:
org 100h
start:
mov al,5
add al,3
mov dl,al
mov ax,2h
int 21h
end start
But the output is the ascii value of 8.I want to know if there is a way to print the decimal value of 8.If yes then how???

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

*тут ничего нету*

»
13 лет назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

You have to convert the number to ascii string yourself, it's assebmler :)

In windows you can try to call "printf" from msvc library

»
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

was in russian interface

»
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Ord('0') = 48

you need to add 48 and 8, then assci value will be 56, and assci character will be '8', to print number with more than 1 digit, you must divide it by 10, until it is not zero.

  • »
    »
    13 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    But then the number will be in reverse order!!
    • »
      »
      »
      13 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      You can use the stack.
    • »
      »
      »
      13 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится
      I think you must to learn programming with one of the languages of high level, then you can try assembler. But now it is to early for you, assembler programming is too complicated for you at this monemt.
      • »
        »
        »
        »
        13 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        I know my rating does not suggest that, but it is not that i am dumb in a high level programming language.I may not be as expert as you are but I know and understand Java.I have just started to learn assembly language 2-3 days ago and so I am very raw at it.Anyways thanks for your efforts:)
»
13 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится
1) You are summing 8-bit numbers, not 16-bit

2) You must greatly increase your skills in "basic algorithms" like dec to string, string to dec, print string by symbols etc.

3) You must learn that though assembler is a very strange language it does not mean you must wrote programs in nasty style. Use procedures, local labels etc like in any normal language.

4) I just wanted to show a short example, but it seems I could not write short %)
.model small
.286

NUM1 equ 317
NUM2 equ 629

.code

start:
mov ax,@data
mov ds,ax

mov bx,NUM1
mov ax, offset firstNumLabel
call printNumWithLabel
mov bx,NUM2
mov ax, offset secondNumLabel
call printNumWithLabel
add bx, NUM1
mov ax, offset sumLabel
call printNumWithLabel

mov ax,4C00h
int 21h

;label in AX
;number in BX
PrintNumWithLabel proc
push ax

call PrintStr
mov ax, bx
call PrintNum
mov ax, offset lineEnd
call PrintStr

pop ax
ret
PrintNumWithLabel endp


;number in AX
PrintNum proc
pusha

cmp ax, 0
jnz wholeNum

mov ax, 0
int 21h
call PrintDigit
jmp printNumEnd

wholeNum:
mov bx, 10
mov di, 0
mov bp, offset tempStr
printNumRepeat:
xor dx, dx
div bx
mov cs:[bp+di],dl
inc di
cmp ax, 0
jne printNumRepeat

printNumRep2:
dec di
mov al, cs:[bp+di]
call printDigit
cmp di, 0
jne printNumRep2

printNumEnd:
popa
ret
tempStr db 8 dup(?)
PrintNum endp

;digit in AX
PrintDigit proc
pusha

xor ah, ah
mov bh, 10
div bh
mov dl, ah
add dl, '0'
mov ah, 2
int 21h

popa
ret
PrintDigit endp

;string pointer in AX
PrintStr proc
pusha

mov dx, ax
mov ah, 9
int 21h

popa
ret
PrintStr endp

.data

firstNumLabel db "First number: ",24h
secondNumLabel db "First number: ",24h
sumLabel db "First number: ",24h
lineEnd db 13,10, 24h

.stack 1024

end start
»
13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Hi,
I'm learning assembler in school this year and I find it very interesting. :)

Here is my code for Sum Of Two Numbers problem.

http://pastebin.com/Wuwi9Azd