Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

defining an array in 16bit assembly nasm

2

Comments

  • fangxifangxi Member Posts: 13
    not a problem i suppose i could comment it real fast

    essentially the changes just do the "2*cx" from our old code

    bx is just being used as another memory location to aid in indexing
    you could probably use any unused registers in its place, or a variable

    [code]
    push bx ; preserve value on the stack

    mov bx, 2 ; bx = 2
    imul bx, cx ; imul is an assembly command for multiplication
    ; the way it was used here is bx = bx*cx

    mov [MyArray+bx], dl ; bx is being used as the index here for your array

    pop bx ; restore previous bx value



    [/code]

    hope this helped
  • fortune2kkfortune2kk Member Posts: 17
    ok sooo if i was to input hello at MyArray[1] it will hold e and MyArray[3] will hold l ? is that what the code is doing.
    sorry im new to assembler
  • fangxifangxi Member Posts: 13
    if the values your passing in through dl are the characters then yes, it should be like you said

    and its ok, i'm relatively new myself
  • fortune2kkfortune2kk Member Posts: 17
    okky sounds what im after well then now time to print the characters out :)
  • fortune2kkfortune2kk Member Posts: 17
    Right now im having a bit of a problem with the prinitng out of the charters. It seems to read the characters into the array but when the PutString is called nothing it echo'd

    main.asm
    [code]
    BITS 16 ;Set code generation to 16 bit mode
    ORG 0x0100;
    SECTION .text;

    MOV CX, 00h ; Sets counter for the number converted to 0
    MOV DL, 00h ; Sets DL to 0

    MAIN:

    MOV CX, 00h ; Sets counter to 0
    call GetString

    ;add black lines here

    MOV CX, 00h ; Sets counter to 0
    Call PutString

    call Exit


    %include "STDIO.asm"
    [/code]



    STDIO.asm
    [code]

    GetString:

    call Getch ; get the character stored in DL

    CMP DL, 0DH ; if Enter is pressed Exit the subroutine
    JE Return

    call Putch ; output the character on screen

    push bx ; preserve value on the stack
    mov bx, 2 ; bx = 2
    imul bx, cx ; imul is an assembly command for multiplication
    ; the way it was used here is bx = bx*cx

    mov [MyArray+bx], dl ; bx is being used as the index here for your array
    pop bx ; restore previous bx value


    INC CX ;add 1 to the counter
    JMP GetString ; loop back to GetString





    Return:
    Ret






    PutString:
    push bx ; preserve value on the stack
    mov bx, 2 ; bx = 2
    imul bx, cx ; imul is an assembly command for multiplication
    ; the way it was used here is bx = bx*cx

    mov AL,[MyArray+bx] ; put the value of the array back into AL
    call Putch ; output the character on screen
    pop bx ; restore previous bx value


    INC CX ;add 1 to the counter
    JMP GetString ; loop back to GetString















    Getch:
    push BX
    mov ah, 7 ; keyboard input subprogram without echo
    int 21h ; read the character into al
    mov dl, al ; move al to dl
    pop BX
    RET ; return



    Putch:
    mov ah, 2h ; display subprogram
    INT 21H ;read the characters from al
    RET ; Return



    Putln: ;new line
    mov dl, 0DH ;Carriage return
    int 21h
    mov dl, 0AH ;Line feed
    int 21H
    RET ; return
    [/code]

    any ideas everything compiles fine but i get no output from the PUtString subroutine

  • fangxifangxi Member Posts: 13
    don't believe i'm any help here
    i've always call C routines for input / output, hopefully someone will come around that knows more than i do
  • anthrax11anthrax11 Member Posts: 511
    If you take a look at your assignment, you'll see that GetString should take di as a parameter for where the array is and PutString should use si. Also, you were told to use the special string instructions ([link=http://faydoc.tripod.com/cpu/lodsb.htm]lodsb[/link]/[link=http://faydoc.tripod.com/cpu/stosb.htm]stosb[/link]) instead of mov. I'd suggest that you try to rewrite the functions accordingly and ask if you get stuck :)

    Also, if a machine is 16-bit, then that doesn't mean you can't address anything smaller than that. On the x86, the smallest addressable unit is always a byte. One character is as big as one byte (8 bits), so all that multiplication by 2 really isn't necessary.
  • fortune2kkfortune2kk Member Posts: 17
    right thanks alot for the input im taking the day off from assembler i will continue tomorrow i will get back to you on my progress ect ect

    thanks alot for all your help

    what u mean about di and si ?
  • anthrax11anthrax11 Member Posts: 511
    Di and si are registers, just like ax, bx, cx, etc. Lodsb/stosb are designed to work with these registers, that's why you were asked to use these registers as parameters to the string functions.
  • fortune2kkfortune2kk Member Posts: 17
    right got ya i will start on this again 2moz with all this in mind thank you :):):):) you have all helped me learn a fare bit thanks sooo much
2
Sign In or Register to comment.