#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    [Assembly] Quick array question


    I am trying to print the contents of a single element in an array I created. Here is what I have..

    .model small

    .stack 100h

    .code

    start:
    my_arr db 1, 3, 5, 6, 2
    mov al, [my_arr]
    mov ah, 2h
    int 21h ; code is relevent to this point
    mov ah, 01h ;
    int 21h ;
    mov dl, al
    mov ah, 2h ;
    int 21h ;
    mov ax, 4c00h ;
    int 21h


    end start

    I've indicated the part of the code that deals with the array, the rest is for something else.

    Anyway, so for example right now it should print a 1. I am getting a character printed, but it's always a triangle. No matter what elements I hardcode into the array it always seems to print a triangle. I'm wondering if mov ah, 2h is the correct way to print an element from an array? Any help on this? Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    928
    You need to keep in mind that DL prints ASCII characters. The ASCII code for the character '1' is 31H. If you try to print the value 1 it will output a control code which may not show up at all.

    I also saw a few other potential problems.

    Code:
    .model small
    
    .stack 100h
    
    .code
    
    start:
      ; What's this data doing in-line with your code?
      ; I may be mistaken (it's been a while since I've touched asm)
      ; But it looks like this array is going to be executed!
      my_arr db 1, 3, 5, 6, 2
      mov al, [my_arr]
      mov ah, 2h
      ; You're trying to print a character here, but you have
      ; yet to put anything in DL
      int 21h
      mov ah, 01h
      int 21h
      mov dl, al
      mov ah, 2h
      int 21h
      mov ax, 4c00h
      int 21h
    end start
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo