DrColonelM

Untitled

Apr 22nd, 2021
655
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. org 100h
  2.  
  3. jmp main
  4.     chrs db  'M','I','M','I','H','S','G','A','M','$'
  5.  
  6. main:
  7.     mov bp, sp
  8.  
  9.     mov ax,offset chrs
  10.     call print_ax_str
  11.     mov ax, offset chrs
  12.     push ax
  13.     push 9
  14.     call reverse
  15.     PRINTN
  16.     mov ax,offset chrs
  17.     call print_ax_str
  18.    
  19.     jmp stop
  20.  
  21. reverse proc
  22.     i equ -2
  23.     temp equ -4
  24.  
  25.     ; First save the old BP  
  26.     push bp
  27.     push bx
  28.     push si
  29.     push ax
  30.     ; Now establish new BP
  31.     mov bp, sp  
  32.     ;make space for 2 local variables
  33.     sub sp, 4
  34.  
  35.     ;write your code here:
  36.     mov si, [bp+12]
  37.    
  38.     mov bx, [bp+10]
  39.     mov [bp+i], bx
  40.     dec [bp+i]      ; [bp+i]=len-1
  41.    
  42.     for:
  43.         ; temp=str[i]
  44.         mov bx, [bp+i]
  45.         mov bx, [si+bx]
  46.         mov [bp+temp], bl
  47.        
  48.         ; str[i]=str[len-1-i]
  49.         mov ax, [bp+i]      ; ax=i
  50.         mov bx, [bp+10]     ; bx=len
  51.         sub bx, ax          ; bx=len-i
  52.         mov bl, [si+bx-1]   ; bx=str[len-i-1]
  53.         xchg ax, bx         ; al=str[len-i-1]
  54.         mov bx, si          ; bx=str
  55.         add bx, [bp+i]      ; bx=str+i
  56.         mov [bx], al        ; str[i]=str[len-i-1]
  57.        
  58.         ; str[len-1-i]=temp
  59.         mov ax, [bp+i]      ; ax=i
  60.         mov bx, [bp+10]     ; bx=len
  61.         sub bx, ax          ; bx=len-i
  62.         mov al, [bp+temp]   ; al=temp
  63.         mov [si+bx-1], al   ; str[len-i-1]=temp
  64.        
  65.         ; i--
  66.         dec [bp+i]
  67.        
  68.         ; i>=len/2
  69.         mov ax, [bp+10]     ; ax=len
  70.         shr ax, 1           ; ax=len/2
  71.        
  72.         cmp [bp+i], ax      ; i-len/2
  73.         jae for
  74.        
  75.        
  76.  
  77.  
  78.     mov sp, bp
  79.     ; Restore OLD BP
  80.     pop ax
  81.     pop si
  82.     pop bx
  83.     pop bp
  84.     ret 4
  85. reverse endp
  86.  
  87. stop:
  88.     mov ah, 0
  89.     int 16h
  90.     ret
  91.  
  92. include magshimim.inc
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×