Assembly code elements of array -


i want write assembly code, following commands:array of 4 elements, read elements user , store them, display array proper message , multiply each element 2 , have problems, first of all:
wrote code:

.model small .stack 100h .data arr db  1,2,3,4,4,4,3,1,2 msg1    db  'the elements of array : $' msg2    db 0dh, 0ah,'the value after multiply 2:   $' .code main proc      mov ax, @data     mov ds, ax      mov cx, 9     mov bx, 0      mov ah,9     lea dx, msg1     int 21h  display1:     mov al, arr[bx]     mov ah, 2     add al, 30h     mov dl, al     int 21h     inc bx loop display1      mov ah,9     lea dx, msg2     int 21h      xor cx, cx     xor bx, bx     mov cx, 9     mov bx, 0 multiplay: mov al, 2 mul arr[bx] mov ah, 2 add al, 30h mov dl, al int 21h inc bx loop multiplay  mov ah, 4ch int 21h main endp end main 


output:

the elements of array : 123444312 value after multiply 2:246888624 

it running well, when i'm trying ask user enter number result isn't given number in decimal digit (that gives form ascii code!)

.model small .stack 100h .data arr db      4 dup (?) msg1    db 0dh, 0ah,    'the elements of array : $' msg2    db 0dh, 0ah,    'the value after multiply 2: $' msg3    db 0dh, 0ah,    'enter 4 elements (numbers) : $' .code main proc      mov ax, @data     mov ds, ax      mov cx, 4     mov bx, 0      mov ah,9     lea dx, msg3     int 21h input:          ;this input elements of array     mov al, arr[bx]     mov ah, 1     sub al, 30h     ; convert ascii     mov dl, al     int 21h     inc bx loop input      mov ah,9     lea dx, msg1     int 21h      xor cx, cx     xor bx, bx     mov cx, 4     mov bx, 0  display1:       ;output elements of array     mov al, arr[bx]     mov ah, 2        add al, 30h ; convert ascii     mov dl, al     int 21h     inc bx loop display1      mov ah,9     lea dx, msg2     int 21h      xor cx, cx     xor bx, bx     mov cx, 4     mov bx, 0 multiplay:      mov al, 2     mul arr[bx]     mov ah, 2     add al, 30h  ; convert ascii     mov dl, al     int 21h     inc bx loop multiplay  mov ah, 4ch int 21h main endp end main 

the problem in : output, display1 , multiplay functions.
output:

enter 4 elements (numbers) : 1234 elements of array : 0000 value after multiplay 2: 0000 

how can correct them?

you have input block messed up, use character before read it, , read array instead of writing. should work better:

input:              ;this input elements of array     mov ah, 1       ; read char echo function     int 21h         ; character returned in al     sub al, 30h     ; convert ascii     mov arr[bx], al ; store array     inc bx     loop input 

ps: learn use debugger can find own mistakes.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -