Hi. Can anybody help me how to shorten my code? This is for a calculator gui using assembly language.

.model small

range macro x,y         ;set cursor
    mov ah, 02
    mov bh, 00
    mov cx, 00
    mov dh, x
    mov dl, y
    int 10h
endm

display macro char
    mov ah, 02
    mov dl, char
    int 21h
endm 


.data

upBorder    db 220, 220, 220, '$'
leftBorder  db 221, '$'    
downBorder  db 223, 223, 223, '$'
rightBorder db 222, '$' 

extraUpBorder   db 220, 220, 220, 220, 220, '$'
extraDownBorder db 223, 223, 223, 223, 223, '$' 

textFieldUp    db 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, '$'
textFieldLeft  db 221, '$'     
textFieldDown  db 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, '$'
textFieldRight db 222, '$'  
textFieldLeft_1 db 221, '$'
textFieldRight_1 db 222, '$'

up    db 220, 220, 220, 220, 220, 220, 220, '$'
left  db 221, '$'
down  db 223, 223, 223, 223, 223, 223, 223, '$'
right db 222, '$'   

del db 'DEL', '$'
ce  db 'CE' , '$'
c   db 'C'  , '$' 

xorLabel db 'XOR', '$'
orLabel  db 'OR' , '$' 
andLabel db 'AND', '$'
modLabel db 'MOD', '$'




.code

.startup  

;----textfield-----------

range 0, 1
  mov ah, 09
  lea dx, textFieldUp
  int 21h

range 1, 1 
  mov ah, 09
  lea dx, textFieldLeft
  int 21h   

range 2, 1
  mov ah, 09
  lea dx, textFieldDown
  int 21h

range 1, 23
  mov ah, 09
  lea dx, textFieldRight
  int 21h  

;--------------------------  

;-----backspace------------

range 3, 1
  mov ah, 09
  lea dx, up
  int 21h

range 4, 1
  mov ah, 09
  lea dx, left
  int 21h

range 5, 1
  mov ah, 09
  lea dx, down
  int 21h

range 4, 7
  mov ah, 09
  lea dx, right
  int 21h

range 4, 3
  mov ah, 09
  lea dx, del
  int 21h 

;--------------------------  

;-----CE------------

range 3, 9
  mov ah, 09
  lea dx, up
  int 21h

range 4, 9
  mov ah, 09
  lea dx, left
  int 21h

range 5, 9
  mov ah, 09
  lea dx, down
  int 21h

range 4, 15
  mov ah, 09
  lea dx, right
  int 21h

range 4, 12
  mov ah, 09
  lea dx, ce
  int 21h

;--------------------------  

;-----c--------------------

range 3, 17
  mov ah, 09
  lea dx, up
  int 21h

range 4, 17
  mov ah, 09
  lea dx, left
  int 21h

range 5, 17
  mov ah, 09
  lea dx, down
  int 21h

range 4, 23
  mov ah, 09
  lea dx, right
  int 21h

range 4, 20
  mov ah, 09
  lea dx, c
  int 21h  



;-----7--------------------

range 6, 1
  mov ah, 09
  lea dx, upBorder
  int 21h

range 7, 1
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 8, 1
  mov ah, 09
  lea dx, downBorder
  int 21h

range 7, 3
  mov ah, 09
  lea dx, rightBorder
  int 21h

range 7, 2
  display 37h

;--------------------------  


;-----8-------------------- 

range 6, 5
  mov ah, 09
  lea dx, upBorder
  int 21h

range 7, 5
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 8, 5
  mov ah, 09
  lea dx, downBorder
  int 21h

range 7, 7
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 7, 6
  display 38h   

;--------------------------  


;-----9--------------------

range 6, 9
  mov ah, 09
  lea dx, upBorder
  int 21h

range 7, 9
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 8, 9
  mov ah, 09
  lea dx, downBorder
  int 21h

range 7, 11
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 7, 10
  display 39h 

;--------------------------  


;-----4--------------------

range 9, 1
  mov ah, 09
  lea dx, upBorder
  int 21h

range 10, 1
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 11, 1
  mov ah, 09
  lea dx, downBorder
  int 21h

range 10, 3
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 10, 2
  display 34h

;--------------------------  


;-----5--------------------

range 9, 5
  mov ah, 09
  lea dx, upBorder
  int 21h

range 10, 5
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 11, 5
  mov ah, 09
  lea dx, downBorder
  int 21h

range 10, 7
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 10, 6
  display 35h

;--------------------------  


;-----6--------------------

range 9, 9
  mov ah, 09
  lea dx, upBorder
  int 21h

range 10, 9
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 11, 9
  mov ah, 09
  lea dx, downBorder
  int 21h

range 10, 11
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 10, 10
  display 36h

;--------------------------  


;-----1--------------------

range 12, 1
  mov ah, 09
  lea dx, upBorder
  int 21h

range 13, 1
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 14, 1
  mov ah, 09
  lea dx, downBorder
  int 21h

range 13, 3
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 13, 2
  display 31h

;--------------------------  


;-----2--------------------

range 12, 5
  mov ah, 09
  lea dx, upBorder
  int 21h

range 13, 5
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 14, 5
  mov ah, 09
  lea dx, downBorder
  int 21h

range 13, 7
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 13, 6
  display 32h

;--------------------------  


;-----3--------------------

range 12, 9
  mov ah, 09
  lea dx, upBorder
  int 21h

range 13, 9
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 14, 9
  mov ah, 09
  lea dx, downBorder
  int 21h

range 13, 11
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 13, 10
  display 33h

;--------------------------  

;------0--------------------

range 15, 1
  mov ah, 09
  lea dx, up
  int 21h

range 16, 1
  mov ah, 09
  lea dx, left
  int 21h

range 17, 1
  mov ah, 09
  lea dx, down
  int 21h

range 16, 7
  mov ah, 09
  lea dx, right
  int 21h

range 16, 4
  display 30h

;-------------------------- 

;-----.--------------------

range 15, 9
  mov ah, 09
  lea dx, upBorder
  int 21h

range 16, 9
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 17, 9
  mov ah, 09
  lea dx, downBorder
  int 21h

range 16, 11
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 16, 10
  display 2Eh

;--------------------------

;-----A--------------------

range 18, 1
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 1
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 1
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 3
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 2
  display 41h

;-------------------------- 

;-----B--------------------

range 18, 5
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 5
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 5
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 7
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 6
  display 42h

;-------------------------- 

;-----C--------------------

range 18, 9
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 9
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 9
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 11
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 10
  display 43h

;--------------------------  

;-----D--------------------

range 18, 13
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 13
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 13
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 15
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 14
  display 44h

;--------------------------  

;-----E--------------------

range 18, 17
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 17
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 17
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 19
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 18
  display 45h

;--------------------------

;-----F--------------------

range 18, 21
  mov ah, 09
  lea dx, upBorder
  int 21h

range 19, 21
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 20, 21
  mov ah, 09
  lea dx, downBorder
  int 21h

range 19, 23
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 19, 22
  display 46h

;--------------------------

;-----/--------------------

range 6, 13
  mov ah, 09
  lea dx, upBorder
  int 21h

range 7, 13
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 8, 13
  mov ah, 09
  lea dx, downBorder
  int 21h

range 7, 15
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 7, 14
  display 2fh

;-------------------------- 

;-----*--------------------

range 9, 13
  mov ah, 09
  lea dx, upBorder
  int 21h

range 10, 13
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 11, 13
  mov ah, 09
  lea dx, downBorder
  int 21h

range 10, 15
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 10, 14
  display 2ah

;--------------------------

;-----(-)--------------------

range 12, 13
  mov ah, 09
  lea dx, upBorder
  int 21h

range 13, 13
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 14, 13
  mov ah, 09
  lea dx, downBorder
  int 21h

range 13, 15
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 13, 14
  display 2dh

;--------------------------

;-----+--------------------

range 15, 13
  mov ah, 09
  lea dx, upBorder
  int 21h

range 16, 13
  mov ah, 09
  lea dx, leftBorder
  int 21h

range 17, 13
  mov ah, 09
  lea dx, downBorder
  int 21h

range 16, 15
  mov ah, 09
  lea dx, rightBorder
  int 21h 

range 16, 14
  display 2bh

;--------------------------  

;-----XOR--------------------

range 6, 17
  mov ah, 09
  lea dx, up
  int 21h

range 7, 17
  mov ah, 09
  lea dx, left
  int 21h

range 8, 17
  mov ah, 09
  lea dx, down
  int 21h

range 7, 23
  mov ah, 09
  lea dx, right
  int 21h 

range 7, 19
  mov ah, 09
  lea dx, xorLabel
  int 21h


;--------------------------

;-----OR--------------------

range 9, 17
  mov ah, 09
  lea dx, up
  int 21h

range 10, 17
  mov ah, 09
  lea dx, left
  int 21h

range 11, 17
  mov ah, 09
  lea dx, down
  int 21h

range 10, 23
  mov ah, 09
  lea dx, right
  int 21h 

range 10, 19
  mov ah, 09
  lea dx, orLabel
  int 21h


;--------------------------  

;-----AND--------------------

range 12, 17
  mov ah, 09
  lea dx, up
  int 21h

range 13, 17
  mov ah, 09
  lea dx, left
  int 21h

range 14, 17
  mov ah, 09
  lea dx, down
  int 21h

range 13, 23
  mov ah, 09
  lea dx, right
  int 21h 

range 13, 19
  mov ah, 09
  lea dx, andLabel
  int 21h


;-------------------------- 

;-----MOD--------------------

range 15, 17
  mov ah, 09
  lea dx, up
  int 21h

range 16, 17
  mov ah, 09
  lea dx, left
  int 21h

range 17, 17
  mov ah, 09
  lea dx, down
  int 21h

range 16, 23
  mov ah, 09
  lea dx, right
  int 21h 

range 16, 19
  mov ah, 09
  lea dx, modLabel
  int 21h


;--------------------------












.exit
end

Thank you.

Hi,
First, forgive my possible errors.
In your code there are a lot of calls to the range macro and after that an "mov ah, 09", a lea instruction and a call to an interrupt.
I know that sometimes some of these is not present, but you could create another macro with another parameter that simply calls range, executes "mov ah, 09", the lea instruction and the call to the interrupt.
When necessary, you employ the new macro and in the other places, you employ range.
Once more, forgive my mistakes.

Oh, I get it. Thank you. My code is shorter now. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.