0

I am really new to assembly programming and i am learning to experiment with the few things i am learning by myself and class. So, my goal is to display a number stored in a register. When i run the program, it displays the character value of the number, so if i were to display the number itself how would i do that. Here is my code, please kindly suggest me where i made my mistake. Until now we have been taught the move instructions and few other basic things in assembly.

#fasm#

mov ah,2

mov bh,66
add bh,1

mov dl,bh


int 21h
int 20h
Jester
  • 56,577
  • 4
  • 81
  • 125
Melissa
  • 41
  • 9
  • You will have to convert your number to text. Plenty of examples for that. For a 2 digit number, just divide by 10 and convert the quotient and the remainder to ascii by adding `'0'` (`48`). – Jester Jun 20 '15 at 17:11
  • `int 21h` with `ah = 2` does not display the *number* that is in `dl`. It displays the *character* that is in `dl`, which means it assumes it's an ASCII encoded character. According to the [ASCII table](http://www.asciitable.com/), if you had `67` in `dl`, then you probably saw a character `C` displayed. – lurker Jun 20 '15 at 18:42
  • @Jester:- Thanks for your advise. I was scanning online for tutorials on fasm assembler but couldn't find any. Then i looked at this guy's tutorial, he is using the 8086 assembler and i tried his code in my fasm assembler and it worked fine. I don't know if that's the right thing to do or do i have to stick to my boring lecturer notes which is so limited. Here is a code that he is used in his tutorial to display a character input. He wrote it in 8086 assembler, i tried it in fasm as follows:- #fasm# org 100h mov ah,1h int 21h mov dl,al mov ah,2h int 21h int 20h – Melissa Jun 20 '15 at 23:01

2 Answers2

0
use16 ;generate 16bit opcodes
org 0100h ;code offset for .COM program

 mov ax,1976 ;ax = number to display

 xor cx,cx ;cx = count = 0
 mov bx,10 ;bx = number base = 10
.stack:
 xor dx,dx ;dx:ax for div
 div bx ;dx:ax = dx:ax div base
 add dx,'0' ;dx into ascii
 push dx ;stack it
 inc cx ;increment counter
 test ax,ax ;do again if not 0
 jnz .stack
 mov ah,02h ;DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT
.write:
 pop dx ;unstack it
 int 21h ;write
 loop .write ;for each in count

 mov ah,08h ;DOS 1+ - CHARACTER INPUT WITHOUT ECHO
 int 21h ;read

 int 20h ;DOS 1+ - TERMINATE PROGRAM
NoName
  • 1
  • 2
  • 1
    Code only answers are hard to use. Please explain what this code does. At least *this is assembly code for a .com program that does this and that ...* – Serge Ballesta Jan 26 '16 at 11:40
0

You can use win32 api (example below). I would suggest you to search for Iczelion tutorials. They're in MASM. FASM Iczelion examples are here.


format PE GUI 4.0
entry start

; macros for `invoke`, `cinvoke`, ...
include 'win32ax.inc'

; code section
section '.text' code readable writable executable
     ; text buffer for the number to display
     buffer  rb 64  ; 64 bytes

     ; program start
  start:

     ; our number
     mov     eax, 1234

     ; printing EAX to buffer
     cinvoke wsprintf, buffer, '%d', eax

     ; terminate string with zero
     mov     [buffer + eax], 0

     ; showing message
     invoke  MessageBox, 0, buffer, 'result', MB_OK

     ; calling exit
     invoke  ExitProcess, 0

section '.idata' import readable writable
     library   kernel32, 'KERNEL32.DLL',\
               user32,   'USER32.DLL'

     include   'api\kernel32.inc'
     include   'api\user32.inc'
Bill
  • 61
  • 5