Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

how to store 3 decimal numbers into an operand

help if you can

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 05 April 2015 - 07:36 AM

org 100h


mov ah,00h
mov al,13h  ;set video mode to 320X200
int 10h


mov ah,09h
mov dx,offset string ;choose hight (320 max)
int 21h


mov al,00h
int 16h      ;read first digit (3 max)
mov cl,al
mov bl,0dh  ;first digit is a must
mov al,00h
int 16h
mov ch,al    ;if enter is pressed the
cmp bl,ch    ;program will accept only 
je accepted1 ;the first digit
mov al,00h
int 16h 
mov ah,al    ;if enter is pressed the
cmp bl,ah    ;program will accept only
je accepted2 ;two digits
mov si,00h
add si,cl
shl si,4
add si,ch
shl si,4     ;the program accepts all
add si,ah    ;3 digits
push si 
jmp width


accepted1:mov si,00h
          add si,cl  ;one digit
          jmp width


accepted2:mov si,00h
          add si,cl
          shl si,4  ;twi digits
          add si,ch
          jmp width




width:mov ah,09h
      mov dx,offset string2 ;hight accepted
      int 21h
      mov ah,09h
      mov dx,offset string3 ;choose width (200 max)
      int 21h
      mov al,00h
      int 16h      ;read first digit (3max)
      mov cl,al
      mov bl,0dh
      mov al,00h  ;first digit is must
      int 16h
      mov ch,al
      cmp bl,ch        ;if enter is pressed only
      je accepted3     ;the first digit is accepted
      mov al,00h
      int 16h
      mov ah,al
      cmp bl,ah      ;if enter is pressed 
      je accepted4   ;only 2 digits are 
      mov si,00h     ;accepted
      add si,cl
      shl si,4       ;accepts all 3 digits
      add si,ch
      shl si,4
      add si,ah
      jmp execute 
      
accepted3:mov si,00h
          add si,cl   ;one digit
          jmp execute


accepted4:mov si,00h
          add si,cl   ;two digits
          shl si,4
          add si,ch
          jmp execute
          
          
execute:mov ah,02h   ;sets cursor
        mov dx,0000h
        int 10h
        mov ah,0ah
        mov al,20h    ;clears the screen
        mov cx,1000h
        int 10h 
        mov cx,0    ;starts executing
        mov dx,0    ;the shape of the
        mov al,15   ;square with pixels
 repeat:mov ah,0ch
        int 10h
        inc cx
        cmp si,cx   ;prints pixels until
        jae repeat  ;the digits in si mach 
        pop si      ;to the digits in cx
        push cx
        mov cx,0
        mov dx,0
        mov al,15
repeat2:mov ah,0ch
        int 10h
        inc dx
        cmp dx,si
        ja repeat2  ;prints pixels until
        push dx     ;the digits in si mach 
        pop cx      ;to the digits in dx
        mov dx,0
        mov al,15
repeat3:mov ah,0ch
        int 10h
        inc dx      ;prints pixels until
        cmp dx,si   ;the digits in si mach
        ja repeat3  ;to the digits in dx
        pop dx
        mov si,cx
        mov cx,0
        mov al,15   ;prints pixels until
repeat4:mov ah,0ch  ;the digits in si mach
        int 10h     ;to the digits in cx
        inc cx
        cmp si,cx
        jae repeat4
repeat5:mov al,00h
        int 16h
        mov bl,0dh  ;repeats this stage
        cmp bl,dx   ;until enter is pressed
        je exit
        jmp repeat5 
        
        
exit:mov ah,02h   ;sets cursor
     mov dx,0000h
     int 10h
     mov ah,0ah
     mov al,20h    ;clears the screen
     mov cx,1000h
     int 10h 
     mov ah,09h
     mov dx,offset string4 ;press 3 to exit
     int 21h
repeat6:mov al,00h
        int 16h           ;if user presses 3
        mov bl,33h        ;the program will
        cmp bl,al         ;close
        je close_program
        jmp repeat 6
        
close_program:mov ax,4c00h
              int 21h       ;closes the program
              
              
string db  "choose hight (320max)",10,13,"$"
string2 db "hight accepted",10,13,"$"
string3 db "choose width (200max)",10,13,"$"             
string4 db "press 3 to exit",10,13,"$"     
i know that in the program it tries to put 4 bits of data into a 16 bit operand but i want to ask is it possible to store 3 decimal numbers each 4 bits that are stored in 8 bit operands and put these values into one 16 bit operand from the first to the last example:
bl=3 decimal
al=2 decimal  --> dx=321 decimal
cl=1decimal          

Edited by dargueta, 07 April 2015 - 05:09 PM.


#2 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 05 April 2015 - 12:50 PM

if someone recommend a tutorial it would be nice thank you.



#3 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 07 April 2015 - 05:10 PM

So you're saying you want something like dx = (cl * 100) + (bl * 10) + al?


sudo rm -rf / && echo $'Sanitize your inputs!'


#4 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 10 April 2015 - 02:19 AM

i kinda figured out how to do it but im stuck with another problem i have 3 numbers in memory cells 1000h-1002h and need to convert the numbers in ther from hex to dec is it possible?



#5 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 11 April 2015 - 05:11 PM

Well the numbers are just stored as raw binary in memory. All that you need to do is change how you represent them in strings or when you print them out. And yes, that's possible.


sudo rm -rf / && echo $'Sanitize your inputs!'


#6 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 18 April 2015 - 07:14 AM

thank you for the information! 

is there any tutorials on the forum how to do it?



#7 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 18 April 2015 - 05:58 PM

Technically yes, but there's a lot of cruft around it that'll probably confuse you. Here's how to convert an integer into a decimal string. Let's say we want to convert the number 123 into a string. To get the lowest digit, we do:

 

123 % 10 = 3

 

To convert the number 3 into the ASCII character '3', all we need to do is add the ASCII value '0':

 

'0' + 3 = '3'

 

This only works for ASCII, specifically the digits 0-9. To keep converting, we divide by ten, discarding the remainder...

 

123 / 10 = 12

 

...and continue with our conversion:

 

12 % 10 = 2

'0' + 2 = '2'

12 / 10 = 1

 

1 % 10 = 1

'0' + 1 = '1'

1 / 10 = 0

 

Concatenated: "123"

 

Stop when you hit 0. Make sure you take into account the case where you could be converting the number 0 to a string!


Edited by dargueta, 18 April 2015 - 05:59 PM.

sudo rm -rf / && echo $'Sanitize your inputs!'


#8 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 19 April 2015 - 06:24 AM

thanks for the information! 

one last question what does % mean?



#9 zika

zika

    CC Regular

  • Member
  • PipPipPip
  • 26 posts

Posted 19 April 2015 - 09:15 AM

thanks for the information! 

one last question what does % mean?

it's mean remain for example:

11/2 = 2 and remain is 1

8 / 3 = 2 and remain 2 



#10 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 19 April 2015 - 09:26 AM

thank you! 

i will keep writing the program now and ask questions later if i encounter problems if its ok



#11 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 19 April 2015 - 02:10 PM

Cool. See you soon!  :)


sudo rm -rf / && echo $'Sanitize your inputs!'


#12 globaltourist

globaltourist

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 23 May 2015 - 04:49 AM

org 100h
 
mov ah,00h
mov al,13h   ;sets graphics mode to 320x200 pixels
int 10h
 
mov ah,09h
mov dx,offset str   ;print string
int 21h
 
mov ah,00h
int 16h
 
mov cl,31h
mov ch,32h
mov dl,33h 
 
cmp al,cl
je square         ;compares the values of                                    
cmp al,cl         ;cl,ch,dl with the charecter
je triangle       ;with the character stored in ah
cmp al,dl
je exit
 
triangle:
call width
mov cx,320    
mov dx,200   
mov al,15   
repeat2:mov ah,0ch   ;ignore this part not ready yet
       int 10h
       inc cx         
       cmp bx,cx     
       jae repeat2   
 
 
 
square:
call width
push bx
              
call hight
pop bx
mov cx,0    
mov dx,0    
mov al,15   
repeat1:mov ah,0ch
       int 10h
       inc cx        ;starts printing the 
       cmp bx,cx     ;the width with white 
       jae repeat1   ;pixels 
       mov cx,0      
       inc dx
       dec si
       cmp si,0h
       jne repeat1
 
mov ah,02h   
mov dx,0000h
int 10h        ;clear screen
mov ah,0ah
mov al,20h    
mov cx,1000h
int 10h 
       
mov ah,09h
mov dx,offset str    ;print string
int 21h                  
                 
mov ah,00h
int 16h
 
mov cl,31h
mov ch,32h
mov dl,33h 
 
cmp al,cl
je square         ;compares the values of                                    
cmp al,cl         ;cl,ch,dl with the charecter
je triangle       ;with the character stored in ah
cmp al,dl
je exit
 
 
exit:
ret
 
width proc
restart:
mov ah,09h
mov dx,offset str1
int 21h
 
mov cl,0dh
mov bx,1000h
mov ah,00       
int 16h
cmp cl,al
je restart  ;asks for hight again
mov [bx],al
inc bx
mov ah,00
int 16h
cmp cl,al
je execute1 ;execute 1 digits
mov [bx],al
inc bx
mov ah,00       
int 16h
cmp cl,al
je execute2 ;execute 2 digits
mov [bx],al
 
mov ah,00001111b
and [bx],ah
dec bx
and [bx],ah       ;transforms ascii 30-39
dec bx            ;into 0-9 for easy operation
and [bx],ah 
 
xor ax,ax
mov al,10 
mov cx,0000h
mov cl,[bx] 
mul cl
inc bx
mov cl,al
add cl,[bx]
mov al,10         ;adds the values from 3 
mul cl            ;adresses into one regester
inc bx            
mov cl,al
inc bx
mov [bx],00h
dec bx
add cx,[bx] 
jmp stop
 
execute1:
mov [bx],al        ;moves one number from 
mov ah,00001111b   ;adress into one regester
and [bx],ah
xor ax,ax
mov cl,[bx]
jmp stop
 
execute2:
mov [bx],al 
mov ah,00001111b
and [bx],ah
dec bx
and [bx],ah         ;adds the values from 2
xor ax,ax           ;adresses into one regester
mov al,10 
mov cx,0000h
mov cl,[bx] 
mul cl
inc bx
mov cl,al
add cl,[bx]
 
stop:
mov bx,cx
ret
width endp 
 
 
 
hight proc
restart1:
mov ah,09h
mov dx,offset str2
int 21h
 
mov cl,0dh
mov bx,1000h
mov ah,00       
int 16h
cmp cl,al
je restart1  ;asks for hight again
mov [bx],al
inc bx
mov ah,00
int 16h
cmp cl,al
je execute3 ;execute 1 digits
mov [bx],al
inc bx
mov ah,00       
int 16h
cmp cl,al
je execute4 ;execute 2 digits
mov [bx],al
 
mov ah,00001111b
and [bx],ah
dec bx
and [bx],ah       ;transforms ascii 30-39
dec bx            ;into 0-9 for easy operation
and [bx],ah 
 
xor ax,ax
mov al,10 
mov cx,0000h
mov cl,[bx] 
mul cl
inc bx
mov cl,al
add cl,[bx]
mov al,10         ;adds the values from 3 
mul cl            ;adresses into one regester
inc bx            
mov cl,al
inc bx
mov [bx],00h
dec bx
add cx,[bx] 
jmp stop1
 
execute3:
mov [bx],al        ;moves one number from 
mov ah,00001111b   ;adress into one regester
and [bx],ah
xor ax,ax
mov cl,[bx]
jmp stop1
 
execute4:
mov [bx],al 
mov ah,00001111b
and [bx],ah
dec bx
and [bx],ah         ;adds the values from 2
xor ax,ax           ;adresses into one regester
mov al,10 
mov cx,0000h
mov cl,[bx] 
mul cl
inc bx
mov cl,al
add cl,[bx]
 
stop1:
mov si,cx
ret
hight endp 
 
str db "Would you like to draw a box(1) or a triangle(2)? for exit press 3",10,13,"$"
str1 db "enter width (320 max)",10,13,"$"
str2 db "enter hight (200max)",10,13,"$"
 
i have a new problem after i enter the hight and the width and it starts printing the square (triangle code part not ready yet) it prints over the 3 strings. what should i add in order to clean the screen and print the square on a clear screen (i have added a picture)20150523_154035.jpg

sorry for photo position :)) but still the problem is understandable.

the square is the white spot